1 /* SPDX-License-Identifier: GPL-2.0 */
3 * xHCI host controller driver
5 * Copyright (C) 2013 Xenia Ragiadakou
7 * Author: Xenia Ragiadakou
8 * Email : burzalodowa@gmail.com
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 #define XHCI_MSG_MAX 500
30 DECLARE_EVENT_CLASS(xhci_log_msg
,
31 TP_PROTO(struct va_format
*vaf
),
33 TP_STRUCT__entry(__dynamic_array(char, msg
, XHCI_MSG_MAX
)),
35 vsnprintf(__get_str(msg
), XHCI_MSG_MAX
, vaf
->fmt
, *vaf
->va
);
37 TP_printk("%s", __get_str(msg
))
40 DEFINE_EVENT(xhci_log_msg
, xhci_dbg_address
,
41 TP_PROTO(struct va_format
*vaf
),
45 DEFINE_EVENT(xhci_log_msg
, xhci_dbg_context_change
,
46 TP_PROTO(struct va_format
*vaf
),
50 DEFINE_EVENT(xhci_log_msg
, xhci_dbg_quirks
,
51 TP_PROTO(struct va_format
*vaf
),
55 DEFINE_EVENT(xhci_log_msg
, xhci_dbg_reset_ep
,
56 TP_PROTO(struct va_format
*vaf
),
60 DEFINE_EVENT(xhci_log_msg
, xhci_dbg_cancel_urb
,
61 TP_PROTO(struct va_format
*vaf
),
65 DEFINE_EVENT(xhci_log_msg
, xhci_dbg_init
,
66 TP_PROTO(struct va_format
*vaf
),
70 DEFINE_EVENT(xhci_log_msg
, xhci_dbg_ring_expansion
,
71 TP_PROTO(struct va_format
*vaf
),
75 DECLARE_EVENT_CLASS(xhci_log_ctx
,
76 TP_PROTO(struct xhci_hcd
*xhci
, struct xhci_container_ctx
*ctx
,
78 TP_ARGS(xhci
, ctx
, ep_num
),
81 __field(unsigned, ctx_type
)
82 __field(dma_addr_t
, ctx_dma
)
84 __field(unsigned, ctx_ep_num
)
86 __dynamic_array(u32
, ctx_data
,
87 ((HCC_64BYTE_CONTEXT(xhci
->hcc_params
) + 1) * 8) *
88 ((ctx
->type
== XHCI_CTX_TYPE_INPUT
) + ep_num
+ 1))
91 struct usb_device
*udev
;
93 udev
= to_usb_device(xhci_to_hcd(xhci
)->self
.controller
);
94 __entry
->ctx_64
= HCC_64BYTE_CONTEXT(xhci
->hcc_params
);
95 __entry
->ctx_type
= ctx
->type
;
96 __entry
->ctx_dma
= ctx
->dma
;
97 __entry
->ctx_va
= ctx
->bytes
;
98 __entry
->slot_id
= udev
->slot_id
;
99 __entry
->ctx_ep_num
= ep_num
;
100 memcpy(__get_dynamic_array(ctx_data
), ctx
->bytes
,
101 ((HCC_64BYTE_CONTEXT(xhci
->hcc_params
) + 1) * 32) *
102 ((ctx
->type
== XHCI_CTX_TYPE_INPUT
) + ep_num
+ 1));
104 TP_printk("ctx_64=%d, ctx_type=%u, ctx_dma=@%llx, ctx_va=@%p",
105 __entry
->ctx_64
, __entry
->ctx_type
,
106 (unsigned long long) __entry
->ctx_dma
, __entry
->ctx_va
110 DEFINE_EVENT(xhci_log_ctx
, xhci_address_ctx
,
111 TP_PROTO(struct xhci_hcd
*xhci
, struct xhci_container_ctx
*ctx
,
112 unsigned int ep_num
),
113 TP_ARGS(xhci
, ctx
, ep_num
)
116 DECLARE_EVENT_CLASS(xhci_log_trb
,
117 TP_PROTO(struct xhci_ring
*ring
, struct xhci_generic_trb
*trb
),
127 __entry
->type
= ring
->type
;
128 __entry
->field0
= le32_to_cpu(trb
->field
[0]);
129 __entry
->field1
= le32_to_cpu(trb
->field
[1]);
130 __entry
->field2
= le32_to_cpu(trb
->field
[2]);
131 __entry
->field3
= le32_to_cpu(trb
->field
[3]);
133 TP_printk("%s: %s", xhci_ring_type_string(__entry
->type
),
134 xhci_decode_trb(__entry
->field0
, __entry
->field1
,
135 __entry
->field2
, __entry
->field3
)
139 DEFINE_EVENT(xhci_log_trb
, xhci_handle_event
,
140 TP_PROTO(struct xhci_ring
*ring
, struct xhci_generic_trb
*trb
),
144 DEFINE_EVENT(xhci_log_trb
, xhci_handle_command
,
145 TP_PROTO(struct xhci_ring
*ring
, struct xhci_generic_trb
*trb
),
149 DEFINE_EVENT(xhci_log_trb
, xhci_handle_transfer
,
150 TP_PROTO(struct xhci_ring
*ring
, struct xhci_generic_trb
*trb
),
154 DEFINE_EVENT(xhci_log_trb
, xhci_queue_trb
,
155 TP_PROTO(struct xhci_ring
*ring
, struct xhci_generic_trb
*trb
),
159 DEFINE_EVENT(xhci_log_trb
, xhci_dbc_handle_event
,
160 TP_PROTO(struct xhci_ring
*ring
, struct xhci_generic_trb
*trb
),
164 DEFINE_EVENT(xhci_log_trb
, xhci_dbc_handle_transfer
,
165 TP_PROTO(struct xhci_ring
*ring
, struct xhci_generic_trb
*trb
),
169 DEFINE_EVENT(xhci_log_trb
, xhci_dbc_gadget_ep_queue
,
170 TP_PROTO(struct xhci_ring
*ring
, struct xhci_generic_trb
*trb
),
174 DECLARE_EVENT_CLASS(xhci_log_free_virt_dev
,
175 TP_PROTO(struct xhci_virt_device
*vdev
),
178 __field(void *, vdev
)
179 __field(unsigned long long, out_ctx
)
180 __field(unsigned long long, in_ctx
)
181 __field(u8
, fake_port
)
182 __field(u8
, real_port
)
183 __field(u16
, current_mel
)
187 __entry
->vdev
= vdev
;
188 __entry
->in_ctx
= (unsigned long long) vdev
->in_ctx
->dma
;
189 __entry
->out_ctx
= (unsigned long long) vdev
->out_ctx
->dma
;
190 __entry
->fake_port
= (u8
) vdev
->fake_port
;
191 __entry
->real_port
= (u8
) vdev
->real_port
;
192 __entry
->current_mel
= (u16
) vdev
->current_mel
;
194 TP_printk("vdev %p ctx %llx | %llx fake_port %d real_port %d current_mel %d",
195 __entry
->vdev
, __entry
->in_ctx
, __entry
->out_ctx
,
196 __entry
->fake_port
, __entry
->real_port
, __entry
->current_mel
200 DEFINE_EVENT(xhci_log_free_virt_dev
, xhci_free_virt_device
,
201 TP_PROTO(struct xhci_virt_device
*vdev
),
205 DECLARE_EVENT_CLASS(xhci_log_virt_dev
,
206 TP_PROTO(struct xhci_virt_device
*vdev
),
209 __field(void *, vdev
)
210 __field(unsigned long long, out_ctx
)
211 __field(unsigned long long, in_ctx
)
217 __field(int, slot_id
)
220 __entry
->vdev
= vdev
;
221 __entry
->in_ctx
= (unsigned long long) vdev
->in_ctx
->dma
;
222 __entry
->out_ctx
= (unsigned long long) vdev
->out_ctx
->dma
;
223 __entry
->devnum
= vdev
->udev
->devnum
;
224 __entry
->state
= vdev
->udev
->state
;
225 __entry
->speed
= vdev
->udev
->speed
;
226 __entry
->portnum
= vdev
->udev
->portnum
;
227 __entry
->level
= vdev
->udev
->level
;
228 __entry
->slot_id
= vdev
->udev
->slot_id
;
230 TP_printk("vdev %p ctx %llx | %llx num %d state %d speed %d port %d level %d slot %d",
231 __entry
->vdev
, __entry
->in_ctx
, __entry
->out_ctx
,
232 __entry
->devnum
, __entry
->state
, __entry
->speed
,
233 __entry
->portnum
, __entry
->level
, __entry
->slot_id
237 DEFINE_EVENT(xhci_log_virt_dev
, xhci_alloc_virt_device
,
238 TP_PROTO(struct xhci_virt_device
*vdev
),
242 DEFINE_EVENT(xhci_log_virt_dev
, xhci_setup_device
,
243 TP_PROTO(struct xhci_virt_device
*vdev
),
247 DEFINE_EVENT(xhci_log_virt_dev
, xhci_setup_addressable_virt_device
,
248 TP_PROTO(struct xhci_virt_device
*vdev
),
252 DEFINE_EVENT(xhci_log_virt_dev
, xhci_stop_device
,
253 TP_PROTO(struct xhci_virt_device
*vdev
),
257 DECLARE_EVENT_CLASS(xhci_log_urb
,
258 TP_PROTO(struct urb
*urb
),
262 __field(unsigned int, pipe
)
263 __field(unsigned int, stream
)
265 __field(unsigned int, flags
)
266 __field(int, num_mapped_sgs
)
267 __field(int, num_sgs
)
273 __field(int, slot_id
)
277 __entry
->pipe
= urb
->pipe
;
278 __entry
->stream
= urb
->stream_id
;
279 __entry
->status
= urb
->status
;
280 __entry
->flags
= urb
->transfer_flags
;
281 __entry
->num_mapped_sgs
= urb
->num_mapped_sgs
;
282 __entry
->num_sgs
= urb
->num_sgs
;
283 __entry
->length
= urb
->transfer_buffer_length
;
284 __entry
->actual
= urb
->actual_length
;
285 __entry
->epnum
= usb_endpoint_num(&urb
->ep
->desc
);
286 __entry
->dir_in
= usb_endpoint_dir_in(&urb
->ep
->desc
);
287 __entry
->type
= usb_endpoint_type(&urb
->ep
->desc
);
288 __entry
->slot_id
= urb
->dev
->slot_id
;
290 TP_printk("ep%d%s-%s: urb %p pipe %u slot %d length %d/%d sgs %d/%d stream %d flags %08x",
291 __entry
->epnum
, __entry
->dir_in
? "in" : "out",
292 __print_symbolic(__entry
->type
,
293 { USB_ENDPOINT_XFER_INT
, "intr" },
294 { USB_ENDPOINT_XFER_CONTROL
, "control" },
295 { USB_ENDPOINT_XFER_BULK
, "bulk" },
296 { USB_ENDPOINT_XFER_ISOC
, "isoc" }),
297 __entry
->urb
, __entry
->pipe
, __entry
->slot_id
,
298 __entry
->actual
, __entry
->length
, __entry
->num_mapped_sgs
,
299 __entry
->num_sgs
, __entry
->stream
, __entry
->flags
303 DEFINE_EVENT(xhci_log_urb
, xhci_urb_enqueue
,
304 TP_PROTO(struct urb
*urb
),
308 DEFINE_EVENT(xhci_log_urb
, xhci_urb_giveback
,
309 TP_PROTO(struct urb
*urb
),
313 DEFINE_EVENT(xhci_log_urb
, xhci_urb_dequeue
,
314 TP_PROTO(struct urb
*urb
),
318 DECLARE_EVENT_CLASS(xhci_log_ep_ctx
,
319 TP_PROTO(struct xhci_ep_ctx
*ctx
),
325 __field(u32
, tx_info
)
328 __entry
->info
= le32_to_cpu(ctx
->ep_info
);
329 __entry
->info2
= le32_to_cpu(ctx
->ep_info2
);
330 __entry
->deq
= le64_to_cpu(ctx
->deq
);
331 __entry
->tx_info
= le32_to_cpu(ctx
->tx_info
);
333 TP_printk("%s", xhci_decode_ep_context(__entry
->info
,
334 __entry
->info2
, __entry
->deq
, __entry
->tx_info
)
338 DEFINE_EVENT(xhci_log_ep_ctx
, xhci_handle_cmd_stop_ep
,
339 TP_PROTO(struct xhci_ep_ctx
*ctx
),
343 DEFINE_EVENT(xhci_log_ep_ctx
, xhci_handle_cmd_set_deq_ep
,
344 TP_PROTO(struct xhci_ep_ctx
*ctx
),
348 DEFINE_EVENT(xhci_log_ep_ctx
, xhci_handle_cmd_reset_ep
,
349 TP_PROTO(struct xhci_ep_ctx
*ctx
),
353 DEFINE_EVENT(xhci_log_ep_ctx
, xhci_handle_cmd_config_ep
,
354 TP_PROTO(struct xhci_ep_ctx
*ctx
),
358 DEFINE_EVENT(xhci_log_ep_ctx
, xhci_add_endpoint
,
359 TP_PROTO(struct xhci_ep_ctx
*ctx
),
363 DECLARE_EVENT_CLASS(xhci_log_slot_ctx
,
364 TP_PROTO(struct xhci_slot_ctx
*ctx
),
369 __field(u32
, tt_info
)
373 __entry
->info
= le32_to_cpu(ctx
->dev_info
);
374 __entry
->info2
= le32_to_cpu(ctx
->dev_info2
);
375 __entry
->tt_info
= le64_to_cpu(ctx
->tt_info
);
376 __entry
->state
= le32_to_cpu(ctx
->dev_state
);
378 TP_printk("%s", xhci_decode_slot_context(__entry
->info
,
379 __entry
->info2
, __entry
->tt_info
,
384 DEFINE_EVENT(xhci_log_slot_ctx
, xhci_alloc_dev
,
385 TP_PROTO(struct xhci_slot_ctx
*ctx
),
389 DEFINE_EVENT(xhci_log_slot_ctx
, xhci_free_dev
,
390 TP_PROTO(struct xhci_slot_ctx
*ctx
),
394 DEFINE_EVENT(xhci_log_slot_ctx
, xhci_handle_cmd_disable_slot
,
395 TP_PROTO(struct xhci_slot_ctx
*ctx
),
399 DEFINE_EVENT(xhci_log_slot_ctx
, xhci_discover_or_reset_device
,
400 TP_PROTO(struct xhci_slot_ctx
*ctx
),
404 DEFINE_EVENT(xhci_log_slot_ctx
, xhci_setup_device_slot
,
405 TP_PROTO(struct xhci_slot_ctx
*ctx
),
409 DEFINE_EVENT(xhci_log_slot_ctx
, xhci_handle_cmd_addr_dev
,
410 TP_PROTO(struct xhci_slot_ctx
*ctx
),
414 DEFINE_EVENT(xhci_log_slot_ctx
, xhci_handle_cmd_reset_dev
,
415 TP_PROTO(struct xhci_slot_ctx
*ctx
),
419 DEFINE_EVENT(xhci_log_slot_ctx
, xhci_handle_cmd_set_deq
,
420 TP_PROTO(struct xhci_slot_ctx
*ctx
),
424 DEFINE_EVENT(xhci_log_slot_ctx
, xhci_configure_endpoint
,
425 TP_PROTO(struct xhci_slot_ctx
*ctx
),
429 DECLARE_EVENT_CLASS(xhci_log_ctrl_ctx
,
430 TP_PROTO(struct xhci_input_control_ctx
*ctrl_ctx
),
437 __entry
->drop
= le32_to_cpu(ctrl_ctx
->drop_flags
);
438 __entry
->add
= le32_to_cpu(ctrl_ctx
->add_flags
);
440 TP_printk("%s", xhci_decode_ctrl_ctx(__entry
->drop
, __entry
->add
)
444 DEFINE_EVENT(xhci_log_ctrl_ctx
, xhci_address_ctrl_ctx
,
445 TP_PROTO(struct xhci_input_control_ctx
*ctrl_ctx
),
449 DEFINE_EVENT(xhci_log_ctrl_ctx
, xhci_configure_endpoint_ctrl_ctx
,
450 TP_PROTO(struct xhci_input_control_ctx
*ctrl_ctx
),
454 DECLARE_EVENT_CLASS(xhci_log_ring
,
455 TP_PROTO(struct xhci_ring
*ring
),
459 __field(void *, ring
)
460 __field(dma_addr_t
, enq
)
461 __field(dma_addr_t
, deq
)
462 __field(dma_addr_t
, enq_seg
)
463 __field(dma_addr_t
, deq_seg
)
464 __field(unsigned int, num_segs
)
465 __field(unsigned int, stream_id
)
466 __field(unsigned int, cycle_state
)
467 __field(unsigned int, num_trbs_free
)
468 __field(unsigned int, bounce_buf_len
)
471 __entry
->ring
= ring
;
472 __entry
->type
= ring
->type
;
473 __entry
->num_segs
= ring
->num_segs
;
474 __entry
->stream_id
= ring
->stream_id
;
475 __entry
->enq_seg
= ring
->enq_seg
->dma
;
476 __entry
->deq_seg
= ring
->deq_seg
->dma
;
477 __entry
->cycle_state
= ring
->cycle_state
;
478 __entry
->num_trbs_free
= ring
->num_trbs_free
;
479 __entry
->bounce_buf_len
= ring
->bounce_buf_len
;
480 __entry
->enq
= xhci_trb_virt_to_dma(ring
->enq_seg
, ring
->enqueue
);
481 __entry
->deq
= xhci_trb_virt_to_dma(ring
->deq_seg
, ring
->dequeue
);
483 TP_printk("%s %p: enq %pad(%pad) deq %pad(%pad) segs %d stream %d free_trbs %d bounce %d cycle %d",
484 xhci_ring_type_string(__entry
->type
), __entry
->ring
,
485 &__entry
->enq
, &__entry
->enq_seg
,
486 &__entry
->deq
, &__entry
->deq_seg
,
489 __entry
->num_trbs_free
,
490 __entry
->bounce_buf_len
,
495 DEFINE_EVENT(xhci_log_ring
, xhci_ring_alloc
,
496 TP_PROTO(struct xhci_ring
*ring
),
500 DEFINE_EVENT(xhci_log_ring
, xhci_ring_free
,
501 TP_PROTO(struct xhci_ring
*ring
),
505 DEFINE_EVENT(xhci_log_ring
, xhci_ring_expansion
,
506 TP_PROTO(struct xhci_ring
*ring
),
510 DEFINE_EVENT(xhci_log_ring
, xhci_inc_enq
,
511 TP_PROTO(struct xhci_ring
*ring
),
515 DEFINE_EVENT(xhci_log_ring
, xhci_inc_deq
,
516 TP_PROTO(struct xhci_ring
*ring
),
520 DECLARE_EVENT_CLASS(xhci_log_portsc
,
521 TP_PROTO(u32 portnum
, u32 portsc
),
522 TP_ARGS(portnum
, portsc
),
524 __field(u32
, portnum
)
528 __entry
->portnum
= portnum
;
529 __entry
->portsc
= portsc
;
531 TP_printk("port-%d: %s",
533 xhci_decode_portsc(__entry
->portsc
)
537 DEFINE_EVENT(xhci_log_portsc
, xhci_handle_port_status
,
538 TP_PROTO(u32 portnum
, u32 portsc
),
539 TP_ARGS(portnum
, portsc
)
542 DEFINE_EVENT(xhci_log_portsc
, xhci_get_port_status
,
543 TP_PROTO(u32 portnum
, u32 portsc
),
544 TP_ARGS(portnum
, portsc
)
547 DEFINE_EVENT(xhci_log_portsc
, xhci_hub_status_data
,
548 TP_PROTO(u32 portnum
, u32 portsc
),
549 TP_ARGS(portnum
, portsc
)
552 DECLARE_EVENT_CLASS(xhci_log_doorbell
,
553 TP_PROTO(u32 slot
, u32 doorbell
),
554 TP_ARGS(slot
, doorbell
),
557 __field(u32
, doorbell
)
560 __entry
->slot
= slot
;
561 __entry
->doorbell
= doorbell
;
563 TP_printk("Ring doorbell for %s",
564 xhci_decode_doorbell(__entry
->slot
, __entry
->doorbell
)
568 DEFINE_EVENT(xhci_log_doorbell
, xhci_ring_ep_doorbell
,
569 TP_PROTO(u32 slot
, u32 doorbell
),
570 TP_ARGS(slot
, doorbell
)
573 DEFINE_EVENT(xhci_log_doorbell
, xhci_ring_host_doorbell
,
574 TP_PROTO(u32 slot
, u32 doorbell
),
575 TP_ARGS(slot
, doorbell
)
578 DECLARE_EVENT_CLASS(xhci_dbc_log_request
,
579 TP_PROTO(struct dbc_request
*req
),
582 __field(struct dbc_request
*, req
)
584 __field(unsigned int, actual
)
585 __field(unsigned int, length
)
590 __entry
->dir
= req
->direction
;
591 __entry
->actual
= req
->actual
;
592 __entry
->length
= req
->length
;
593 __entry
->status
= req
->status
;
595 TP_printk("%s: req %p length %u/%u ==> %d",
596 __entry
->dir
? "bulk-in" : "bulk-out",
597 __entry
->req
, __entry
->actual
,
598 __entry
->length
, __entry
->status
602 DEFINE_EVENT(xhci_dbc_log_request
, xhci_dbc_alloc_request
,
603 TP_PROTO(struct dbc_request
*req
),
607 DEFINE_EVENT(xhci_dbc_log_request
, xhci_dbc_free_request
,
608 TP_PROTO(struct dbc_request
*req
),
612 DEFINE_EVENT(xhci_dbc_log_request
, xhci_dbc_queue_request
,
613 TP_PROTO(struct dbc_request
*req
),
617 DEFINE_EVENT(xhci_dbc_log_request
, xhci_dbc_giveback_request
,
618 TP_PROTO(struct dbc_request
*req
),
621 #endif /* __XHCI_TRACE_H */
623 /* this part must be outside header guard */
625 #undef TRACE_INCLUDE_PATH
626 #define TRACE_INCLUDE_PATH .
628 #undef TRACE_INCLUDE_FILE
629 #define TRACE_INCLUDE_FILE xhci-trace
631 #include <trace/define_trace.h>