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)
83 __dynamic_array(u32, ctx_data,
84 ((HCC_64BYTE_CONTEXT(xhci->hcc_params) + 1) * 8) *
85 ((ctx->type == XHCI_CTX_TYPE_INPUT) + ep_num + 1))
89 __entry->ctx_64 = HCC_64BYTE_CONTEXT(xhci->hcc_params);
90 __entry->ctx_type = ctx->type;
91 __entry->ctx_dma = ctx->dma;
92 __entry->ctx_va = ctx->bytes;
93 __entry->ctx_ep_num = ep_num;
94 memcpy(__get_dynamic_array(ctx_data), ctx->bytes,
95 ((HCC_64BYTE_CONTEXT(xhci->hcc_params) + 1) * 32) *
96 ((ctx->type == XHCI_CTX_TYPE_INPUT) + ep_num + 1));
98 TP_printk("ctx_64=%d, ctx_type=%u, ctx_dma=@%llx, ctx_va=@%p",
99 __entry->ctx_64, __entry->ctx_type,
100 (unsigned long long) __entry->ctx_dma, __entry->ctx_va
104 DEFINE_EVENT(xhci_log_ctx, xhci_address_ctx,
105 TP_PROTO(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx,
106 unsigned int ep_num),
107 TP_ARGS(xhci, ctx, ep_num)
110 DECLARE_EVENT_CLASS(xhci_log_trb,
111 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
121 __entry->type = ring->type;
122 __entry->field0 = le32_to_cpu(trb->field[0]);
123 __entry->field1 = le32_to_cpu(trb->field[1]);
124 __entry->field2 = le32_to_cpu(trb->field[2]);
125 __entry->field3 = le32_to_cpu(trb->field[3]);
127 TP_printk("%s: %s", xhci_ring_type_string(__entry->type),
128 xhci_decode_trb(__get_buf(XHCI_MSG_MAX), XHCI_MSG_MAX, __entry->field0,
129 __entry->field1, __entry->field2, __entry->field3)
133 DEFINE_EVENT(xhci_log_trb, xhci_handle_event,
134 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
138 DEFINE_EVENT(xhci_log_trb, xhci_handle_command,
139 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
143 DEFINE_EVENT(xhci_log_trb, xhci_handle_transfer,
144 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
148 DEFINE_EVENT(xhci_log_trb, xhci_queue_trb,
149 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
153 DEFINE_EVENT(xhci_log_trb, xhci_dbc_handle_event,
154 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
158 DEFINE_EVENT(xhci_log_trb, xhci_dbc_handle_transfer,
159 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
163 DEFINE_EVENT(xhci_log_trb, xhci_dbc_gadget_ep_queue,
164 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
168 DECLARE_EVENT_CLASS(xhci_log_free_virt_dev,
169 TP_PROTO(struct xhci_virt_device *vdev),
172 __field(void *, vdev)
173 __field(unsigned long long, out_ctx)
174 __field(unsigned long long, in_ctx)
175 __field(int, slot_id)
176 __field(u16, current_mel)
180 __entry->vdev = vdev;
181 __entry->in_ctx = (unsigned long long) vdev->in_ctx->dma;
182 __entry->out_ctx = (unsigned long long) vdev->out_ctx->dma;
183 __entry->slot_id = (int) vdev->slot_id;
184 __entry->current_mel = (u16) vdev->current_mel;
186 TP_printk("vdev %p slot %d ctx %llx | %llx current_mel %d",
187 __entry->vdev, __entry->slot_id, __entry->in_ctx,
188 __entry->out_ctx, __entry->current_mel
192 DEFINE_EVENT(xhci_log_free_virt_dev, xhci_free_virt_device,
193 TP_PROTO(struct xhci_virt_device *vdev),
197 DECLARE_EVENT_CLASS(xhci_log_virt_dev,
198 TP_PROTO(struct xhci_virt_device *vdev),
201 __field(void *, vdev)
202 __field(unsigned long long, out_ctx)
203 __field(unsigned long long, in_ctx)
209 __field(int, slot_id)
212 __entry->vdev = vdev;
213 __entry->in_ctx = (unsigned long long) vdev->in_ctx->dma;
214 __entry->out_ctx = (unsigned long long) vdev->out_ctx->dma;
215 __entry->devnum = vdev->udev->devnum;
216 __entry->state = vdev->udev->state;
217 __entry->speed = vdev->udev->speed;
218 __entry->portnum = vdev->udev->portnum;
219 __entry->level = vdev->udev->level;
220 __entry->slot_id = vdev->udev->slot_id;
222 TP_printk("vdev %p ctx %llx | %llx num %d state %d speed %d port %d level %d slot %d",
223 __entry->vdev, __entry->in_ctx, __entry->out_ctx,
224 __entry->devnum, __entry->state, __entry->speed,
225 __entry->portnum, __entry->level, __entry->slot_id
229 DEFINE_EVENT(xhci_log_virt_dev, xhci_alloc_virt_device,
230 TP_PROTO(struct xhci_virt_device *vdev),
234 DEFINE_EVENT(xhci_log_virt_dev, xhci_setup_device,
235 TP_PROTO(struct xhci_virt_device *vdev),
239 DEFINE_EVENT(xhci_log_virt_dev, xhci_setup_addressable_virt_device,
240 TP_PROTO(struct xhci_virt_device *vdev),
244 DEFINE_EVENT(xhci_log_virt_dev, xhci_stop_device,
245 TP_PROTO(struct xhci_virt_device *vdev),
249 DECLARE_EVENT_CLASS(xhci_log_urb,
250 TP_PROTO(struct urb *urb),
253 __string(devname, dev_name(&urb->dev->dev))
255 __field(unsigned int, pipe)
256 __field(unsigned int, stream)
258 __field(unsigned int, flags)
259 __field(int, num_mapped_sgs)
260 __field(int, num_sgs)
266 __field(int, slot_id)
269 __assign_str(devname);
271 __entry->pipe = urb->pipe;
272 __entry->stream = urb->stream_id;
273 __entry->status = urb->status;
274 __entry->flags = urb->transfer_flags;
275 __entry->num_mapped_sgs = urb->num_mapped_sgs;
276 __entry->num_sgs = urb->num_sgs;
277 __entry->length = urb->transfer_buffer_length;
278 __entry->actual = urb->actual_length;
279 __entry->epnum = usb_endpoint_num(&urb->ep->desc);
280 __entry->dir_in = usb_endpoint_dir_in(&urb->ep->desc);
281 __entry->type = usb_endpoint_type(&urb->ep->desc);
282 __entry->slot_id = urb->dev->slot_id;
284 TP_printk("%s ep%d%s-%s: urb %p pipe %u slot %d length %d/%d sgs %d/%d stream %d flags %08x",
286 __entry->epnum, __entry->dir_in ? "in" : "out",
287 __print_symbolic(__entry->type,
288 { USB_ENDPOINT_XFER_INT, "intr" },
289 { USB_ENDPOINT_XFER_CONTROL, "control" },
290 { USB_ENDPOINT_XFER_BULK, "bulk" },
291 { USB_ENDPOINT_XFER_ISOC, "isoc" }),
292 __entry->urb, __entry->pipe, __entry->slot_id,
293 __entry->actual, __entry->length, __entry->num_mapped_sgs,
294 __entry->num_sgs, __entry->stream, __entry->flags
298 DEFINE_EVENT(xhci_log_urb, xhci_urb_enqueue,
299 TP_PROTO(struct urb *urb),
303 DEFINE_EVENT(xhci_log_urb, xhci_urb_giveback,
304 TP_PROTO(struct urb *urb),
308 DEFINE_EVENT(xhci_log_urb, xhci_urb_dequeue,
309 TP_PROTO(struct urb *urb),
313 DECLARE_EVENT_CLASS(xhci_log_ep_ctx,
314 TP_PROTO(struct xhci_ep_ctx *ctx),
320 __field(u32, tx_info)
323 __entry->info = le32_to_cpu(ctx->ep_info);
324 __entry->info2 = le32_to_cpu(ctx->ep_info2);
325 __entry->deq = le64_to_cpu(ctx->deq);
326 __entry->tx_info = le32_to_cpu(ctx->tx_info);
328 TP_printk("%s", xhci_decode_ep_context(__get_buf(XHCI_MSG_MAX),
329 __entry->info, __entry->info2, __entry->deq, __entry->tx_info)
333 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_stop_ep,
334 TP_PROTO(struct xhci_ep_ctx *ctx),
338 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_set_deq_ep,
339 TP_PROTO(struct xhci_ep_ctx *ctx),
343 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_reset_ep,
344 TP_PROTO(struct xhci_ep_ctx *ctx),
348 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_config_ep,
349 TP_PROTO(struct xhci_ep_ctx *ctx),
353 DEFINE_EVENT(xhci_log_ep_ctx, xhci_add_endpoint,
354 TP_PROTO(struct xhci_ep_ctx *ctx),
358 DECLARE_EVENT_CLASS(xhci_log_slot_ctx,
359 TP_PROTO(struct xhci_slot_ctx *ctx),
364 __field(u32, tt_info)
368 __entry->info = le32_to_cpu(ctx->dev_info);
369 __entry->info2 = le32_to_cpu(ctx->dev_info2);
370 __entry->tt_info = le64_to_cpu(ctx->tt_info);
371 __entry->state = le32_to_cpu(ctx->dev_state);
373 TP_printk("%s", xhci_decode_slot_context(__get_buf(XHCI_MSG_MAX),
374 __entry->info, __entry->info2,
375 __entry->tt_info, __entry->state)
379 DEFINE_EVENT(xhci_log_slot_ctx, xhci_alloc_dev,
380 TP_PROTO(struct xhci_slot_ctx *ctx),
384 DEFINE_EVENT(xhci_log_slot_ctx, xhci_free_dev,
385 TP_PROTO(struct xhci_slot_ctx *ctx),
389 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_disable_slot,
390 TP_PROTO(struct xhci_slot_ctx *ctx),
394 DEFINE_EVENT(xhci_log_slot_ctx, xhci_discover_or_reset_device,
395 TP_PROTO(struct xhci_slot_ctx *ctx),
399 DEFINE_EVENT(xhci_log_slot_ctx, xhci_setup_device_slot,
400 TP_PROTO(struct xhci_slot_ctx *ctx),
404 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_addr_dev,
405 TP_PROTO(struct xhci_slot_ctx *ctx),
409 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_reset_dev,
410 TP_PROTO(struct xhci_slot_ctx *ctx),
414 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_set_deq,
415 TP_PROTO(struct xhci_slot_ctx *ctx),
419 DEFINE_EVENT(xhci_log_slot_ctx, xhci_configure_endpoint,
420 TP_PROTO(struct xhci_slot_ctx *ctx),
424 DECLARE_EVENT_CLASS(xhci_log_ctrl_ctx,
425 TP_PROTO(struct xhci_input_control_ctx *ctrl_ctx),
432 __entry->drop = le32_to_cpu(ctrl_ctx->drop_flags);
433 __entry->add = le32_to_cpu(ctrl_ctx->add_flags);
435 TP_printk("%s", xhci_decode_ctrl_ctx(__get_buf(XHCI_MSG_MAX), __entry->drop, __entry->add)
439 DEFINE_EVENT(xhci_log_ctrl_ctx, xhci_address_ctrl_ctx,
440 TP_PROTO(struct xhci_input_control_ctx *ctrl_ctx),
444 DEFINE_EVENT(xhci_log_ctrl_ctx, xhci_configure_endpoint_ctrl_ctx,
445 TP_PROTO(struct xhci_input_control_ctx *ctrl_ctx),
449 DECLARE_EVENT_CLASS(xhci_log_ring,
450 TP_PROTO(struct xhci_ring *ring),
454 __field(void *, ring)
455 __field(dma_addr_t, enq)
456 __field(dma_addr_t, deq)
457 __field(dma_addr_t, enq_seg)
458 __field(dma_addr_t, deq_seg)
459 __field(unsigned int, num_segs)
460 __field(unsigned int, stream_id)
461 __field(unsigned int, cycle_state)
462 __field(unsigned int, bounce_buf_len)
465 __entry->ring = ring;
466 __entry->type = ring->type;
467 __entry->num_segs = ring->num_segs;
468 __entry->stream_id = ring->stream_id;
469 __entry->enq_seg = ring->enq_seg->dma;
470 __entry->deq_seg = ring->deq_seg->dma;
471 __entry->cycle_state = ring->cycle_state;
472 __entry->bounce_buf_len = ring->bounce_buf_len;
473 __entry->enq = xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue);
474 __entry->deq = xhci_trb_virt_to_dma(ring->deq_seg, ring->dequeue);
476 TP_printk("%s %p: enq %pad(%pad) deq %pad(%pad) segs %d stream %d bounce %d cycle %d",
477 xhci_ring_type_string(__entry->type), __entry->ring,
478 &__entry->enq, &__entry->enq_seg,
479 &__entry->deq, &__entry->deq_seg,
482 __entry->bounce_buf_len,
487 DEFINE_EVENT(xhci_log_ring, xhci_ring_alloc,
488 TP_PROTO(struct xhci_ring *ring),
492 DEFINE_EVENT(xhci_log_ring, xhci_ring_free,
493 TP_PROTO(struct xhci_ring *ring),
497 DEFINE_EVENT(xhci_log_ring, xhci_ring_expansion,
498 TP_PROTO(struct xhci_ring *ring),
502 DEFINE_EVENT(xhci_log_ring, xhci_inc_enq,
503 TP_PROTO(struct xhci_ring *ring),
507 DEFINE_EVENT(xhci_log_ring, xhci_inc_deq,
508 TP_PROTO(struct xhci_ring *ring),
512 DECLARE_EVENT_CLASS(xhci_log_portsc,
513 TP_PROTO(struct xhci_port *port, u32 portsc),
514 TP_ARGS(port, portsc),
517 __field(u32, portnum)
521 __entry->busnum = port->rhub->hcd->self.busnum;
522 __entry->portnum = port->hcd_portnum;
523 __entry->portsc = portsc;
525 TP_printk("port %d-%d: %s",
528 xhci_decode_portsc(__get_buf(XHCI_MSG_MAX), __entry->portsc)
532 DEFINE_EVENT(xhci_log_portsc, xhci_handle_port_status,
533 TP_PROTO(struct xhci_port *port, u32 portsc),
534 TP_ARGS(port, portsc)
537 DEFINE_EVENT(xhci_log_portsc, xhci_get_port_status,
538 TP_PROTO(struct xhci_port *port, u32 portsc),
539 TP_ARGS(port, portsc)
542 DEFINE_EVENT(xhci_log_portsc, xhci_hub_status_data,
543 TP_PROTO(struct xhci_port *port, u32 portsc),
544 TP_ARGS(port, portsc)
547 DECLARE_EVENT_CLASS(xhci_log_doorbell,
548 TP_PROTO(u32 slot, u32 doorbell),
549 TP_ARGS(slot, doorbell),
552 __field(u32, doorbell)
555 __entry->slot = slot;
556 __entry->doorbell = doorbell;
558 TP_printk("Ring doorbell for %s",
559 xhci_decode_doorbell(__get_buf(XHCI_MSG_MAX), __entry->slot, __entry->doorbell)
563 DEFINE_EVENT(xhci_log_doorbell, xhci_ring_ep_doorbell,
564 TP_PROTO(u32 slot, u32 doorbell),
565 TP_ARGS(slot, doorbell)
568 DEFINE_EVENT(xhci_log_doorbell, xhci_ring_host_doorbell,
569 TP_PROTO(u32 slot, u32 doorbell),
570 TP_ARGS(slot, doorbell)
573 DECLARE_EVENT_CLASS(xhci_dbc_log_request,
574 TP_PROTO(struct dbc_request *req),
577 __field(struct dbc_request *, req)
579 __field(unsigned int, actual)
580 __field(unsigned int, length)
585 __entry->dir = req->direction;
586 __entry->actual = req->actual;
587 __entry->length = req->length;
588 __entry->status = req->status;
590 TP_printk("%s: req %p length %u/%u ==> %d",
591 __entry->dir ? "bulk-in" : "bulk-out",
592 __entry->req, __entry->actual,
593 __entry->length, __entry->status
597 DEFINE_EVENT(xhci_dbc_log_request, xhci_dbc_alloc_request,
598 TP_PROTO(struct dbc_request *req),
602 DEFINE_EVENT(xhci_dbc_log_request, xhci_dbc_free_request,
603 TP_PROTO(struct dbc_request *req),
607 DEFINE_EVENT(xhci_dbc_log_request, xhci_dbc_queue_request,
608 TP_PROTO(struct dbc_request *req),
612 DEFINE_EVENT(xhci_dbc_log_request, xhci_dbc_giveback_request,
613 TP_PROTO(struct dbc_request *req),
616 #endif /* __XHCI_TRACE_H */
618 /* this part must be outside header guard */
620 #undef TRACE_INCLUDE_PATH
621 #define TRACE_INCLUDE_PATH .
623 #undef TRACE_INCLUDE_FILE
624 #define TRACE_INCLUDE_FILE xhci-trace
626 #include <trace/define_trace.h>