1 /* SPDX-License-Identifier: GPL-2.0 */
3 * xHCI host controller driver
5 * Copyright (C) 2013 Xenia Ragiadakou
7 * Author: Xenia Ragiadakou
12 #define TRACE_SYSTEM xhci-hcd
15 * The TRACE_SYSTEM_VAR defaults to TRACE_SYSTEM, but must be a
16 * legitimate C variable. It is not exported to user space.
18 #undef TRACE_SYSTEM_VAR
19 #define TRACE_SYSTEM_VAR xhci_hcd
21 #if !defined(__XHCI_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
22 #define __XHCI_TRACE_H
24 #include <linux/tracepoint.h>
26 #include "xhci-dbgcap.h"
28 DECLARE_EVENT_CLASS(xhci_log_msg,
29 TP_PROTO(struct va_format *vaf),
31 TP_STRUCT__entry(__vstring(msg, vaf->fmt, vaf->va)),
33 __assign_vstr(msg, vaf->fmt, vaf->va);
35 TP_printk("%s", __get_str(msg))
38 DEFINE_EVENT(xhci_log_msg, xhci_dbg_address,
39 TP_PROTO(struct va_format *vaf),
43 DEFINE_EVENT(xhci_log_msg, xhci_dbg_context_change,
44 TP_PROTO(struct va_format *vaf),
48 DEFINE_EVENT(xhci_log_msg, xhci_dbg_quirks,
49 TP_PROTO(struct va_format *vaf),
53 DEFINE_EVENT(xhci_log_msg, xhci_dbg_reset_ep,
54 TP_PROTO(struct va_format *vaf),
58 DEFINE_EVENT(xhci_log_msg, xhci_dbg_cancel_urb,
59 TP_PROTO(struct va_format *vaf),
63 DEFINE_EVENT(xhci_log_msg, xhci_dbg_init,
64 TP_PROTO(struct va_format *vaf),
68 DEFINE_EVENT(xhci_log_msg, xhci_dbg_ring_expansion,
69 TP_PROTO(struct va_format *vaf),
73 DECLARE_EVENT_CLASS(xhci_log_ctx,
74 TP_PROTO(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx,
76 TP_ARGS(xhci, ctx, ep_num),
79 __field(unsigned, ctx_type)
80 __field(dma_addr_t, ctx_dma)
82 __field(unsigned, ctx_ep_num)
84 __dynamic_array(u32, ctx_data,
85 ((HCC_64BYTE_CONTEXT(xhci->hcc_params) + 1) * 8) *
86 ((ctx->type == XHCI_CTX_TYPE_INPUT) + ep_num + 1))
89 struct usb_device *udev;
91 udev = to_usb_device(xhci_to_hcd(xhci)->self.controller);
92 __entry->ctx_64 = HCC_64BYTE_CONTEXT(xhci->hcc_params);
93 __entry->ctx_type = ctx->type;
94 __entry->ctx_dma = ctx->dma;
95 __entry->ctx_va = ctx->bytes;
96 __entry->slot_id = udev->slot_id;
97 __entry->ctx_ep_num = ep_num;
98 memcpy(__get_dynamic_array(ctx_data), ctx->bytes,
99 ((HCC_64BYTE_CONTEXT(xhci->hcc_params) + 1) * 32) *
100 ((ctx->type == XHCI_CTX_TYPE_INPUT) + ep_num + 1));
102 TP_printk("ctx_64=%d, ctx_type=%u, ctx_dma=@%llx, ctx_va=@%p",
103 __entry->ctx_64, __entry->ctx_type,
104 (unsigned long long) __entry->ctx_dma, __entry->ctx_va
108 DEFINE_EVENT(xhci_log_ctx, xhci_address_ctx,
109 TP_PROTO(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx,
110 unsigned int ep_num),
111 TP_ARGS(xhci, ctx, ep_num)
114 DECLARE_EVENT_CLASS(xhci_log_trb,
115 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
125 __entry->type = ring->type;
126 __entry->field0 = le32_to_cpu(trb->field[0]);
127 __entry->field1 = le32_to_cpu(trb->field[1]);
128 __entry->field2 = le32_to_cpu(trb->field[2]);
129 __entry->field3 = le32_to_cpu(trb->field[3]);
131 TP_printk("%s: %s", xhci_ring_type_string(__entry->type),
132 xhci_decode_trb(__get_buf(XHCI_MSG_MAX), XHCI_MSG_MAX, __entry->field0,
133 __entry->field1, __entry->field2, __entry->field3)
137 DEFINE_EVENT(xhci_log_trb, xhci_handle_event,
138 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
142 DEFINE_EVENT(xhci_log_trb, xhci_handle_command,
143 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
147 DEFINE_EVENT(xhci_log_trb, xhci_handle_transfer,
148 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
152 DEFINE_EVENT(xhci_log_trb, xhci_queue_trb,
153 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
157 DEFINE_EVENT(xhci_log_trb, xhci_dbc_handle_event,
158 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
162 DEFINE_EVENT(xhci_log_trb, xhci_dbc_handle_transfer,
163 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
167 DEFINE_EVENT(xhci_log_trb, xhci_dbc_gadget_ep_queue,
168 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
172 DECLARE_EVENT_CLASS(xhci_log_free_virt_dev,
173 TP_PROTO(struct xhci_virt_device *vdev),
176 __field(void *, vdev)
177 __field(unsigned long long, out_ctx)
178 __field(unsigned long long, in_ctx)
179 __field(u8, fake_port)
180 __field(u8, real_port)
181 __field(u16, current_mel)
185 __entry->vdev = vdev;
186 __entry->in_ctx = (unsigned long long) vdev->in_ctx->dma;
187 __entry->out_ctx = (unsigned long long) vdev->out_ctx->dma;
188 __entry->fake_port = (u8) vdev->fake_port;
189 __entry->real_port = (u8) vdev->real_port;
190 __entry->current_mel = (u16) vdev->current_mel;
192 TP_printk("vdev %p ctx %llx | %llx fake_port %d real_port %d current_mel %d",
193 __entry->vdev, __entry->in_ctx, __entry->out_ctx,
194 __entry->fake_port, __entry->real_port, __entry->current_mel
198 DEFINE_EVENT(xhci_log_free_virt_dev, xhci_free_virt_device,
199 TP_PROTO(struct xhci_virt_device *vdev),
203 DECLARE_EVENT_CLASS(xhci_log_virt_dev,
204 TP_PROTO(struct xhci_virt_device *vdev),
207 __field(void *, vdev)
208 __field(unsigned long long, out_ctx)
209 __field(unsigned long long, in_ctx)
215 __field(int, slot_id)
218 __entry->vdev = vdev;
219 __entry->in_ctx = (unsigned long long) vdev->in_ctx->dma;
220 __entry->out_ctx = (unsigned long long) vdev->out_ctx->dma;
221 __entry->devnum = vdev->udev->devnum;
222 __entry->state = vdev->udev->state;
223 __entry->speed = vdev->udev->speed;
224 __entry->portnum = vdev->udev->portnum;
225 __entry->level = vdev->udev->level;
226 __entry->slot_id = vdev->udev->slot_id;
228 TP_printk("vdev %p ctx %llx | %llx num %d state %d speed %d port %d level %d slot %d",
229 __entry->vdev, __entry->in_ctx, __entry->out_ctx,
230 __entry->devnum, __entry->state, __entry->speed,
231 __entry->portnum, __entry->level, __entry->slot_id
235 DEFINE_EVENT(xhci_log_virt_dev, xhci_alloc_virt_device,
236 TP_PROTO(struct xhci_virt_device *vdev),
240 DEFINE_EVENT(xhci_log_virt_dev, xhci_setup_device,
241 TP_PROTO(struct xhci_virt_device *vdev),
245 DEFINE_EVENT(xhci_log_virt_dev, xhci_setup_addressable_virt_device,
246 TP_PROTO(struct xhci_virt_device *vdev),
250 DEFINE_EVENT(xhci_log_virt_dev, xhci_stop_device,
251 TP_PROTO(struct xhci_virt_device *vdev),
255 DECLARE_EVENT_CLASS(xhci_log_urb,
256 TP_PROTO(struct urb *urb),
260 __field(unsigned int, pipe)
261 __field(unsigned int, stream)
263 __field(unsigned int, flags)
264 __field(int, num_mapped_sgs)
265 __field(int, num_sgs)
271 __field(int, slot_id)
275 __entry->pipe = urb->pipe;
276 __entry->stream = urb->stream_id;
277 __entry->status = urb->status;
278 __entry->flags = urb->transfer_flags;
279 __entry->num_mapped_sgs = urb->num_mapped_sgs;
280 __entry->num_sgs = urb->num_sgs;
281 __entry->length = urb->transfer_buffer_length;
282 __entry->actual = urb->actual_length;
283 __entry->epnum = usb_endpoint_num(&urb->ep->desc);
284 __entry->dir_in = usb_endpoint_dir_in(&urb->ep->desc);
285 __entry->type = usb_endpoint_type(&urb->ep->desc);
286 __entry->slot_id = urb->dev->slot_id;
288 TP_printk("ep%d%s-%s: urb %p pipe %u slot %d length %d/%d sgs %d/%d stream %d flags %08x",
289 __entry->epnum, __entry->dir_in ? "in" : "out",
290 __print_symbolic(__entry->type,
291 { USB_ENDPOINT_XFER_INT, "intr" },
292 { USB_ENDPOINT_XFER_CONTROL, "control" },
293 { USB_ENDPOINT_XFER_BULK, "bulk" },
294 { USB_ENDPOINT_XFER_ISOC, "isoc" }),
295 __entry->urb, __entry->pipe, __entry->slot_id,
296 __entry->actual, __entry->length, __entry->num_mapped_sgs,
297 __entry->num_sgs, __entry->stream, __entry->flags
301 DEFINE_EVENT(xhci_log_urb, xhci_urb_enqueue,
302 TP_PROTO(struct urb *urb),
306 DEFINE_EVENT(xhci_log_urb, xhci_urb_giveback,
307 TP_PROTO(struct urb *urb),
311 DEFINE_EVENT(xhci_log_urb, xhci_urb_dequeue,
312 TP_PROTO(struct urb *urb),
316 DECLARE_EVENT_CLASS(xhci_log_ep_ctx,
317 TP_PROTO(struct xhci_ep_ctx *ctx),
323 __field(u32, tx_info)
326 __entry->info = le32_to_cpu(ctx->ep_info);
327 __entry->info2 = le32_to_cpu(ctx->ep_info2);
328 __entry->deq = le64_to_cpu(ctx->deq);
329 __entry->tx_info = le32_to_cpu(ctx->tx_info);
331 TP_printk("%s", xhci_decode_ep_context(__get_buf(XHCI_MSG_MAX),
332 __entry->info, __entry->info2, __entry->deq, __entry->tx_info)
336 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_stop_ep,
337 TP_PROTO(struct xhci_ep_ctx *ctx),
341 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_set_deq_ep,
342 TP_PROTO(struct xhci_ep_ctx *ctx),
346 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_reset_ep,
347 TP_PROTO(struct xhci_ep_ctx *ctx),
351 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_config_ep,
352 TP_PROTO(struct xhci_ep_ctx *ctx),
356 DEFINE_EVENT(xhci_log_ep_ctx, xhci_add_endpoint,
357 TP_PROTO(struct xhci_ep_ctx *ctx),
361 DECLARE_EVENT_CLASS(xhci_log_slot_ctx,
362 TP_PROTO(struct xhci_slot_ctx *ctx),
367 __field(u32, tt_info)
371 __entry->info = le32_to_cpu(ctx->dev_info);
372 __entry->info2 = le32_to_cpu(ctx->dev_info2);
373 __entry->tt_info = le64_to_cpu(ctx->tt_info);
374 __entry->state = le32_to_cpu(ctx->dev_state);
376 TP_printk("%s", xhci_decode_slot_context(__get_buf(XHCI_MSG_MAX),
377 __entry->info, __entry->info2,
378 __entry->tt_info, __entry->state)
382 DEFINE_EVENT(xhci_log_slot_ctx, xhci_alloc_dev,
383 TP_PROTO(struct xhci_slot_ctx *ctx),
387 DEFINE_EVENT(xhci_log_slot_ctx, xhci_free_dev,
388 TP_PROTO(struct xhci_slot_ctx *ctx),
392 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_disable_slot,
393 TP_PROTO(struct xhci_slot_ctx *ctx),
397 DEFINE_EVENT(xhci_log_slot_ctx, xhci_discover_or_reset_device,
398 TP_PROTO(struct xhci_slot_ctx *ctx),
402 DEFINE_EVENT(xhci_log_slot_ctx, xhci_setup_device_slot,
403 TP_PROTO(struct xhci_slot_ctx *ctx),
407 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_addr_dev,
408 TP_PROTO(struct xhci_slot_ctx *ctx),
412 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_reset_dev,
413 TP_PROTO(struct xhci_slot_ctx *ctx),
417 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_set_deq,
418 TP_PROTO(struct xhci_slot_ctx *ctx),
422 DEFINE_EVENT(xhci_log_slot_ctx, xhci_configure_endpoint,
423 TP_PROTO(struct xhci_slot_ctx *ctx),
427 DECLARE_EVENT_CLASS(xhci_log_ctrl_ctx,
428 TP_PROTO(struct xhci_input_control_ctx *ctrl_ctx),
435 __entry->drop = le32_to_cpu(ctrl_ctx->drop_flags);
436 __entry->add = le32_to_cpu(ctrl_ctx->add_flags);
438 TP_printk("%s", xhci_decode_ctrl_ctx(__get_buf(XHCI_MSG_MAX), __entry->drop, __entry->add)
442 DEFINE_EVENT(xhci_log_ctrl_ctx, xhci_address_ctrl_ctx,
443 TP_PROTO(struct xhci_input_control_ctx *ctrl_ctx),
447 DEFINE_EVENT(xhci_log_ctrl_ctx, xhci_configure_endpoint_ctrl_ctx,
448 TP_PROTO(struct xhci_input_control_ctx *ctrl_ctx),
452 DECLARE_EVENT_CLASS(xhci_log_ring,
453 TP_PROTO(struct xhci_ring *ring),
457 __field(void *, ring)
458 __field(dma_addr_t, enq)
459 __field(dma_addr_t, deq)
460 __field(dma_addr_t, enq_seg)
461 __field(dma_addr_t, deq_seg)
462 __field(unsigned int, num_segs)
463 __field(unsigned int, stream_id)
464 __field(unsigned int, cycle_state)
465 __field(unsigned int, num_trbs_free)
466 __field(unsigned int, bounce_buf_len)
469 __entry->ring = ring;
470 __entry->type = ring->type;
471 __entry->num_segs = ring->num_segs;
472 __entry->stream_id = ring->stream_id;
473 __entry->enq_seg = ring->enq_seg->dma;
474 __entry->deq_seg = ring->deq_seg->dma;
475 __entry->cycle_state = ring->cycle_state;
476 __entry->num_trbs_free = ring->num_trbs_free;
477 __entry->bounce_buf_len = ring->bounce_buf_len;
478 __entry->enq = xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue);
479 __entry->deq = xhci_trb_virt_to_dma(ring->deq_seg, ring->dequeue);
481 TP_printk("%s %p: enq %pad(%pad) deq %pad(%pad) segs %d stream %d free_trbs %d bounce %d cycle %d",
482 xhci_ring_type_string(__entry->type), __entry->ring,
483 &__entry->enq, &__entry->enq_seg,
484 &__entry->deq, &__entry->deq_seg,
487 __entry->num_trbs_free,
488 __entry->bounce_buf_len,
493 DEFINE_EVENT(xhci_log_ring, xhci_ring_alloc,
494 TP_PROTO(struct xhci_ring *ring),
498 DEFINE_EVENT(xhci_log_ring, xhci_ring_free,
499 TP_PROTO(struct xhci_ring *ring),
503 DEFINE_EVENT(xhci_log_ring, xhci_ring_expansion,
504 TP_PROTO(struct xhci_ring *ring),
508 DEFINE_EVENT(xhci_log_ring, xhci_inc_enq,
509 TP_PROTO(struct xhci_ring *ring),
513 DEFINE_EVENT(xhci_log_ring, xhci_inc_deq,
514 TP_PROTO(struct xhci_ring *ring),
518 DECLARE_EVENT_CLASS(xhci_log_portsc,
519 TP_PROTO(u32 portnum, u32 portsc),
520 TP_ARGS(portnum, portsc),
522 __field(u32, portnum)
526 __entry->portnum = portnum;
527 __entry->portsc = portsc;
529 TP_printk("port-%d: %s",
531 xhci_decode_portsc(__get_buf(XHCI_MSG_MAX), __entry->portsc)
535 DEFINE_EVENT(xhci_log_portsc, xhci_handle_port_status,
536 TP_PROTO(u32 portnum, u32 portsc),
537 TP_ARGS(portnum, portsc)
540 DEFINE_EVENT(xhci_log_portsc, xhci_get_port_status,
541 TP_PROTO(u32 portnum, u32 portsc),
542 TP_ARGS(portnum, portsc)
545 DEFINE_EVENT(xhci_log_portsc, xhci_hub_status_data,
546 TP_PROTO(u32 portnum, u32 portsc),
547 TP_ARGS(portnum, portsc)
550 DECLARE_EVENT_CLASS(xhci_log_doorbell,
551 TP_PROTO(u32 slot, u32 doorbell),
552 TP_ARGS(slot, doorbell),
555 __field(u32, doorbell)
558 __entry->slot = slot;
559 __entry->doorbell = doorbell;
561 TP_printk("Ring doorbell for %s",
562 xhci_decode_doorbell(__get_buf(XHCI_MSG_MAX), __entry->slot, __entry->doorbell)
566 DEFINE_EVENT(xhci_log_doorbell, xhci_ring_ep_doorbell,
567 TP_PROTO(u32 slot, u32 doorbell),
568 TP_ARGS(slot, doorbell)
571 DEFINE_EVENT(xhci_log_doorbell, xhci_ring_host_doorbell,
572 TP_PROTO(u32 slot, u32 doorbell),
573 TP_ARGS(slot, doorbell)
576 DECLARE_EVENT_CLASS(xhci_dbc_log_request,
577 TP_PROTO(struct dbc_request *req),
580 __field(struct dbc_request *, req)
582 __field(unsigned int, actual)
583 __field(unsigned int, length)
588 __entry->dir = req->direction;
589 __entry->actual = req->actual;
590 __entry->length = req->length;
591 __entry->status = req->status;
593 TP_printk("%s: req %p length %u/%u ==> %d",
594 __entry->dir ? "bulk-in" : "bulk-out",
595 __entry->req, __entry->actual,
596 __entry->length, __entry->status
600 DEFINE_EVENT(xhci_dbc_log_request, xhci_dbc_alloc_request,
601 TP_PROTO(struct dbc_request *req),
605 DEFINE_EVENT(xhci_dbc_log_request, xhci_dbc_free_request,
606 TP_PROTO(struct dbc_request *req),
610 DEFINE_EVENT(xhci_dbc_log_request, xhci_dbc_queue_request,
611 TP_PROTO(struct dbc_request *req),
615 DEFINE_EVENT(xhci_dbc_log_request, xhci_dbc_giveback_request,
616 TP_PROTO(struct dbc_request *req),
619 #endif /* __XHCI_TRACE_H */
621 /* this part must be outside header guard */
623 #undef TRACE_INCLUDE_PATH
624 #define TRACE_INCLUDE_PATH .
626 #undef TRACE_INCLUDE_FILE
627 #define TRACE_INCLUDE_FILE xhci-trace
629 #include <trace/define_trace.h>