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>
27 #define XHCI_MSG_MAX 500
29 DECLARE_EVENT_CLASS(xhci_log_msg,
30 TP_PROTO(struct va_format *vaf),
32 TP_STRUCT__entry(__dynamic_array(char, msg, XHCI_MSG_MAX)),
34 vsnprintf(__get_str(msg), XHCI_MSG_MAX, vaf->fmt, *vaf->va);
36 TP_printk("%s", __get_str(msg))
39 DEFINE_EVENT(xhci_log_msg, xhci_dbg_address,
40 TP_PROTO(struct va_format *vaf),
44 DEFINE_EVENT(xhci_log_msg, xhci_dbg_context_change,
45 TP_PROTO(struct va_format *vaf),
49 DEFINE_EVENT(xhci_log_msg, xhci_dbg_quirks,
50 TP_PROTO(struct va_format *vaf),
54 DEFINE_EVENT(xhci_log_msg, xhci_dbg_reset_ep,
55 TP_PROTO(struct va_format *vaf),
59 DEFINE_EVENT(xhci_log_msg, xhci_dbg_cancel_urb,
60 TP_PROTO(struct va_format *vaf),
64 DEFINE_EVENT(xhci_log_msg, xhci_dbg_init,
65 TP_PROTO(struct va_format *vaf),
69 DEFINE_EVENT(xhci_log_msg, xhci_dbg_ring_expansion,
70 TP_PROTO(struct va_format *vaf),
74 DECLARE_EVENT_CLASS(xhci_log_ctx,
75 TP_PROTO(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx,
77 TP_ARGS(xhci, ctx, ep_num),
80 __field(unsigned, ctx_type)
81 __field(dma_addr_t, ctx_dma)
83 __field(unsigned, ctx_ep_num)
85 __dynamic_array(u32, ctx_data,
86 ((HCC_64BYTE_CONTEXT(xhci->hcc_params) + 1) * 8) *
87 ((ctx->type == XHCI_CTX_TYPE_INPUT) + ep_num + 1))
90 struct usb_device *udev;
92 udev = to_usb_device(xhci_to_hcd(xhci)->self.controller);
93 __entry->ctx_64 = HCC_64BYTE_CONTEXT(xhci->hcc_params);
94 __entry->ctx_type = ctx->type;
95 __entry->ctx_dma = ctx->dma;
96 __entry->ctx_va = ctx->bytes;
97 __entry->slot_id = udev->slot_id;
98 __entry->ctx_ep_num = ep_num;
99 memcpy(__get_dynamic_array(ctx_data), ctx->bytes,
100 ((HCC_64BYTE_CONTEXT(xhci->hcc_params) + 1) * 32) *
101 ((ctx->type == XHCI_CTX_TYPE_INPUT) + ep_num + 1));
103 TP_printk("ctx_64=%d, ctx_type=%u, ctx_dma=@%llx, ctx_va=@%p",
104 __entry->ctx_64, __entry->ctx_type,
105 (unsigned long long) __entry->ctx_dma, __entry->ctx_va
109 DEFINE_EVENT(xhci_log_ctx, xhci_address_ctx,
110 TP_PROTO(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx,
111 unsigned int ep_num),
112 TP_ARGS(xhci, ctx, ep_num)
115 DECLARE_EVENT_CLASS(xhci_log_trb,
116 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
126 __entry->type = ring->type;
127 __entry->field0 = le32_to_cpu(trb->field[0]);
128 __entry->field1 = le32_to_cpu(trb->field[1]);
129 __entry->field2 = le32_to_cpu(trb->field[2]);
130 __entry->field3 = le32_to_cpu(trb->field[3]);
132 TP_printk("%s: %s", xhci_ring_type_string(__entry->type),
133 xhci_decode_trb(__entry->field0, __entry->field1,
134 __entry->field2, __entry->field3)
138 DEFINE_EVENT(xhci_log_trb, xhci_handle_event,
139 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
143 DEFINE_EVENT(xhci_log_trb, xhci_handle_command,
144 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
148 DEFINE_EVENT(xhci_log_trb, xhci_handle_transfer,
149 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
153 DEFINE_EVENT(xhci_log_trb, xhci_queue_trb,
154 TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
158 DECLARE_EVENT_CLASS(xhci_log_virt_dev,
159 TP_PROTO(struct xhci_virt_device *vdev),
162 __field(void *, vdev)
163 __field(unsigned long long, out_ctx)
164 __field(unsigned long long, in_ctx)
170 __field(int, slot_id)
173 __entry->vdev = vdev;
174 __entry->in_ctx = (unsigned long long) vdev->in_ctx->dma;
175 __entry->out_ctx = (unsigned long long) vdev->out_ctx->dma;
176 __entry->devnum = vdev->udev->devnum;
177 __entry->state = vdev->udev->state;
178 __entry->speed = vdev->udev->speed;
179 __entry->portnum = vdev->udev->portnum;
180 __entry->level = vdev->udev->level;
181 __entry->slot_id = vdev->udev->slot_id;
183 TP_printk("vdev %p ctx %llx | %llx num %d state %d speed %d port %d level %d slot %d",
184 __entry->vdev, __entry->in_ctx, __entry->out_ctx,
185 __entry->devnum, __entry->state, __entry->speed,
186 __entry->portnum, __entry->level, __entry->slot_id
190 DEFINE_EVENT(xhci_log_virt_dev, xhci_alloc_virt_device,
191 TP_PROTO(struct xhci_virt_device *vdev),
195 DEFINE_EVENT(xhci_log_virt_dev, xhci_free_virt_device,
196 TP_PROTO(struct xhci_virt_device *vdev),
200 DEFINE_EVENT(xhci_log_virt_dev, xhci_setup_device,
201 TP_PROTO(struct xhci_virt_device *vdev),
205 DEFINE_EVENT(xhci_log_virt_dev, xhci_setup_addressable_virt_device,
206 TP_PROTO(struct xhci_virt_device *vdev),
210 DEFINE_EVENT(xhci_log_virt_dev, xhci_stop_device,
211 TP_PROTO(struct xhci_virt_device *vdev),
215 DECLARE_EVENT_CLASS(xhci_log_urb,
216 TP_PROTO(struct urb *urb),
220 __field(unsigned int, pipe)
221 __field(unsigned int, stream)
223 __field(unsigned int, flags)
224 __field(int, num_mapped_sgs)
225 __field(int, num_sgs)
231 __field(int, slot_id)
235 __entry->pipe = urb->pipe;
236 __entry->stream = urb->stream_id;
237 __entry->status = urb->status;
238 __entry->flags = urb->transfer_flags;
239 __entry->num_mapped_sgs = urb->num_mapped_sgs;
240 __entry->num_sgs = urb->num_sgs;
241 __entry->length = urb->transfer_buffer_length;
242 __entry->actual = urb->actual_length;
243 __entry->epnum = usb_endpoint_num(&urb->ep->desc);
244 __entry->dir_in = usb_endpoint_dir_in(&urb->ep->desc);
245 __entry->type = usb_endpoint_type(&urb->ep->desc);
246 __entry->slot_id = urb->dev->slot_id;
248 TP_printk("ep%d%s-%s: urb %p pipe %u slot %d length %d/%d sgs %d/%d stream %d flags %08x",
249 __entry->epnum, __entry->dir_in ? "in" : "out",
251 switch (__entry->type) {
252 case USB_ENDPOINT_XFER_INT:
255 case USB_ENDPOINT_XFER_CONTROL:
258 case USB_ENDPOINT_XFER_BULK:
261 case USB_ENDPOINT_XFER_ISOC:
266 } s; }), __entry->urb, __entry->pipe, __entry->slot_id,
267 __entry->actual, __entry->length, __entry->num_mapped_sgs,
268 __entry->num_sgs, __entry->stream, __entry->flags
272 DEFINE_EVENT(xhci_log_urb, xhci_urb_enqueue,
273 TP_PROTO(struct urb *urb),
277 DEFINE_EVENT(xhci_log_urb, xhci_urb_giveback,
278 TP_PROTO(struct urb *urb),
282 DEFINE_EVENT(xhci_log_urb, xhci_urb_dequeue,
283 TP_PROTO(struct urb *urb),
287 DECLARE_EVENT_CLASS(xhci_log_ep_ctx,
288 TP_PROTO(struct xhci_ep_ctx *ctx),
294 __field(u32, tx_info)
297 __entry->info = le32_to_cpu(ctx->ep_info);
298 __entry->info2 = le32_to_cpu(ctx->ep_info2);
299 __entry->deq = le64_to_cpu(ctx->deq);
300 __entry->tx_info = le32_to_cpu(ctx->tx_info);
302 TP_printk("%s", xhci_decode_ep_context(__entry->info,
303 __entry->info2, __entry->deq, __entry->tx_info)
307 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_stop_ep,
308 TP_PROTO(struct xhci_ep_ctx *ctx),
312 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_set_deq_ep,
313 TP_PROTO(struct xhci_ep_ctx *ctx),
317 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_reset_ep,
318 TP_PROTO(struct xhci_ep_ctx *ctx),
322 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_config_ep,
323 TP_PROTO(struct xhci_ep_ctx *ctx),
327 DECLARE_EVENT_CLASS(xhci_log_slot_ctx,
328 TP_PROTO(struct xhci_slot_ctx *ctx),
333 __field(u32, tt_info)
337 __entry->info = le32_to_cpu(ctx->dev_info);
338 __entry->info2 = le32_to_cpu(ctx->dev_info2);
339 __entry->tt_info = le64_to_cpu(ctx->tt_info);
340 __entry->state = le32_to_cpu(ctx->dev_state);
342 TP_printk("%s", xhci_decode_slot_context(__entry->info,
343 __entry->info2, __entry->tt_info,
348 DEFINE_EVENT(xhci_log_slot_ctx, xhci_alloc_dev,
349 TP_PROTO(struct xhci_slot_ctx *ctx),
353 DEFINE_EVENT(xhci_log_slot_ctx, xhci_free_dev,
354 TP_PROTO(struct xhci_slot_ctx *ctx),
358 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_disable_slot,
359 TP_PROTO(struct xhci_slot_ctx *ctx),
363 DEFINE_EVENT(xhci_log_slot_ctx, xhci_discover_or_reset_device,
364 TP_PROTO(struct xhci_slot_ctx *ctx),
368 DEFINE_EVENT(xhci_log_slot_ctx, xhci_setup_device_slot,
369 TP_PROTO(struct xhci_slot_ctx *ctx),
373 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_addr_dev,
374 TP_PROTO(struct xhci_slot_ctx *ctx),
378 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_reset_dev,
379 TP_PROTO(struct xhci_slot_ctx *ctx),
383 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_set_deq,
384 TP_PROTO(struct xhci_slot_ctx *ctx),
388 DEFINE_EVENT(xhci_log_slot_ctx, xhci_configure_endpoint,
389 TP_PROTO(struct xhci_slot_ctx *ctx),
393 DECLARE_EVENT_CLASS(xhci_log_ring,
394 TP_PROTO(struct xhci_ring *ring),
398 __field(void *, ring)
399 __field(dma_addr_t, enq)
400 __field(dma_addr_t, deq)
401 __field(dma_addr_t, enq_seg)
402 __field(dma_addr_t, deq_seg)
403 __field(unsigned int, num_segs)
404 __field(unsigned int, stream_id)
405 __field(unsigned int, cycle_state)
406 __field(unsigned int, num_trbs_free)
407 __field(unsigned int, bounce_buf_len)
410 __entry->ring = ring;
411 __entry->type = ring->type;
412 __entry->num_segs = ring->num_segs;
413 __entry->stream_id = ring->stream_id;
414 __entry->enq_seg = ring->enq_seg->dma;
415 __entry->deq_seg = ring->deq_seg->dma;
416 __entry->cycle_state = ring->cycle_state;
417 __entry->num_trbs_free = ring->num_trbs_free;
418 __entry->bounce_buf_len = ring->bounce_buf_len;
419 __entry->enq = xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue);
420 __entry->deq = xhci_trb_virt_to_dma(ring->deq_seg, ring->dequeue);
422 TP_printk("%s %p: enq %pad(%pad) deq %pad(%pad) segs %d stream %d free_trbs %d bounce %d cycle %d",
423 xhci_ring_type_string(__entry->type), __entry->ring,
424 &__entry->enq, &__entry->enq_seg,
425 &__entry->deq, &__entry->deq_seg,
428 __entry->num_trbs_free,
429 __entry->bounce_buf_len,
434 DEFINE_EVENT(xhci_log_ring, xhci_ring_alloc,
435 TP_PROTO(struct xhci_ring *ring),
439 DEFINE_EVENT(xhci_log_ring, xhci_ring_free,
440 TP_PROTO(struct xhci_ring *ring),
444 DEFINE_EVENT(xhci_log_ring, xhci_ring_expansion,
445 TP_PROTO(struct xhci_ring *ring),
449 DEFINE_EVENT(xhci_log_ring, xhci_inc_enq,
450 TP_PROTO(struct xhci_ring *ring),
454 DEFINE_EVENT(xhci_log_ring, xhci_inc_deq,
455 TP_PROTO(struct xhci_ring *ring),
459 DECLARE_EVENT_CLASS(xhci_log_portsc,
460 TP_PROTO(u32 portnum, u32 portsc),
461 TP_ARGS(portnum, portsc),
463 __field(u32, portnum)
467 __entry->portnum = portnum;
468 __entry->portsc = portsc;
470 TP_printk("port-%d: %s",
472 xhci_decode_portsc(__entry->portsc)
476 DEFINE_EVENT(xhci_log_portsc, xhci_handle_port_status,
477 TP_PROTO(u32 portnum, u32 portsc),
478 TP_ARGS(portnum, portsc)
481 #endif /* __XHCI_TRACE_H */
483 /* this part must be outside header guard */
485 #undef TRACE_INCLUDE_PATH
486 #define TRACE_INCLUDE_PATH .
488 #undef TRACE_INCLUDE_FILE
489 #define TRACE_INCLUDE_FILE xhci-trace
491 #include <trace/define_trace.h>