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