1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * USBSS device controller driver. 4 * Trace support header file. 5 * 6 * Copyright (C) 2018-2019 Cadence. 7 * 8 * Author: Pawel Laszczak <pawell@cadence.com> 9 */ 10 11 #undef TRACE_SYSTEM 12 #define TRACE_SYSTEM cdns3 13 14 #if !defined(__LINUX_CDNS3_TRACE) || defined(TRACE_HEADER_MULTI_READ) 15 #define __LINUX_CDNS3_TRACE 16 17 #include <linux/types.h> 18 #include <linux/tracepoint.h> 19 #include <asm/byteorder.h> 20 #include <linux/usb/ch9.h> 21 #include "core.h" 22 #include "cdns3-gadget.h" 23 #include "cdns3-debug.h" 24 25 #define CDNS3_MSG_MAX 500 26 27 TRACE_EVENT(cdns3_halt, 28 TP_PROTO(struct cdns3_endpoint *ep_priv, u8 halt, u8 flush), 29 TP_ARGS(ep_priv, halt, flush), 30 TP_STRUCT__entry( 31 __string(name, ep_priv->name) 32 __field(u8, halt) 33 __field(u8, flush) 34 ), 35 TP_fast_assign( 36 __assign_str(name, ep_priv->name); 37 __entry->halt = halt; 38 __entry->flush = flush; 39 ), 40 TP_printk("Halt %s for %s: %s", __entry->flush ? " and flush" : "", 41 __get_str(name), __entry->halt ? "set" : "cleared") 42 ); 43 44 TRACE_EVENT(cdns3_wa1, 45 TP_PROTO(struct cdns3_endpoint *ep_priv, char *msg), 46 TP_ARGS(ep_priv, msg), 47 TP_STRUCT__entry( 48 __string(ep_name, ep_priv->name) 49 __string(msg, msg) 50 ), 51 TP_fast_assign( 52 __assign_str(ep_name, ep_priv->name); 53 __assign_str(msg, msg); 54 ), 55 TP_printk("WA1: %s %s", __get_str(ep_name), __get_str(msg)) 56 ); 57 58 TRACE_EVENT(cdns3_wa2, 59 TP_PROTO(struct cdns3_endpoint *ep_priv, char *msg), 60 TP_ARGS(ep_priv, msg), 61 TP_STRUCT__entry( 62 __string(ep_name, ep_priv->name) 63 __string(msg, msg) 64 ), 65 TP_fast_assign( 66 __assign_str(ep_name, ep_priv->name); 67 __assign_str(msg, msg); 68 ), 69 TP_printk("WA2: %s %s", __get_str(ep_name), __get_str(msg)) 70 ); 71 72 DECLARE_EVENT_CLASS(cdns3_log_doorbell, 73 TP_PROTO(const char *ep_name, u32 ep_trbaddr), 74 TP_ARGS(ep_name, ep_trbaddr), 75 TP_STRUCT__entry( 76 __string(name, ep_name) 77 __field(u32, ep_trbaddr) 78 ), 79 TP_fast_assign( 80 __assign_str(name, ep_name); 81 __entry->ep_trbaddr = ep_trbaddr; 82 ), 83 TP_printk("%s, ep_trbaddr %08x", __get_str(name), 84 __entry->ep_trbaddr) 85 ); 86 87 DEFINE_EVENT(cdns3_log_doorbell, cdns3_doorbell_ep0, 88 TP_PROTO(const char *ep_name, u32 ep_trbaddr), 89 TP_ARGS(ep_name, ep_trbaddr) 90 ); 91 92 DEFINE_EVENT(cdns3_log_doorbell, cdns3_doorbell_epx, 93 TP_PROTO(const char *ep_name, u32 ep_trbaddr), 94 TP_ARGS(ep_name, ep_trbaddr) 95 ); 96 97 DECLARE_EVENT_CLASS(cdns3_log_usb_irq, 98 TP_PROTO(struct cdns3_device *priv_dev, u32 usb_ists), 99 TP_ARGS(priv_dev, usb_ists), 100 TP_STRUCT__entry( 101 __field(enum usb_device_speed, speed) 102 __field(u32, usb_ists) 103 __dynamic_array(char, str, CDNS3_MSG_MAX) 104 ), 105 TP_fast_assign( 106 __entry->speed = cdns3_get_speed(priv_dev); 107 __entry->usb_ists = usb_ists; 108 ), 109 TP_printk("%s", cdns3_decode_usb_irq(__get_str(str), __entry->speed, 110 __entry->usb_ists)) 111 ); 112 113 DEFINE_EVENT(cdns3_log_usb_irq, cdns3_usb_irq, 114 TP_PROTO(struct cdns3_device *priv_dev, u32 usb_ists), 115 TP_ARGS(priv_dev, usb_ists) 116 ); 117 118 DECLARE_EVENT_CLASS(cdns3_log_epx_irq, 119 TP_PROTO(struct cdns3_device *priv_dev, struct cdns3_endpoint *priv_ep), 120 TP_ARGS(priv_dev, priv_ep), 121 TP_STRUCT__entry( 122 __string(ep_name, priv_ep->name) 123 __field(u32, ep_sts) 124 __field(u32, ep_traddr) 125 __field(u32, ep_last_sid) 126 __field(u32, use_streams) 127 __dynamic_array(char, str, CDNS3_MSG_MAX) 128 ), 129 TP_fast_assign( 130 __assign_str(ep_name, priv_ep->name); 131 __entry->ep_sts = readl(&priv_dev->regs->ep_sts); 132 __entry->ep_traddr = readl(&priv_dev->regs->ep_traddr); 133 __entry->ep_last_sid = priv_ep->last_stream_id; 134 __entry->use_streams = priv_ep->use_streams; 135 ), 136 TP_printk("%s, ep_traddr: %08x ep_last_sid: %08x use_streams: %d", 137 cdns3_decode_epx_irq(__get_str(str), 138 __get_str(ep_name), 139 __entry->ep_sts), 140 __entry->ep_traddr, 141 __entry->ep_last_sid, 142 __entry->use_streams) 143 ); 144 145 DEFINE_EVENT(cdns3_log_epx_irq, cdns3_epx_irq, 146 TP_PROTO(struct cdns3_device *priv_dev, struct cdns3_endpoint *priv_ep), 147 TP_ARGS(priv_dev, priv_ep) 148 ); 149 150 DECLARE_EVENT_CLASS(cdns3_log_ep0_irq, 151 TP_PROTO(struct cdns3_device *priv_dev, u32 ep_sts), 152 TP_ARGS(priv_dev, ep_sts), 153 TP_STRUCT__entry( 154 __field(int, ep_dir) 155 __field(u32, ep_sts) 156 __dynamic_array(char, str, CDNS3_MSG_MAX) 157 ), 158 TP_fast_assign( 159 __entry->ep_dir = priv_dev->selected_ep; 160 __entry->ep_sts = ep_sts; 161 ), 162 TP_printk("%s", cdns3_decode_ep0_irq(__get_str(str), 163 __entry->ep_dir, 164 __entry->ep_sts)) 165 ); 166 167 DEFINE_EVENT(cdns3_log_ep0_irq, cdns3_ep0_irq, 168 TP_PROTO(struct cdns3_device *priv_dev, u32 ep_sts), 169 TP_ARGS(priv_dev, ep_sts) 170 ); 171 172 DECLARE_EVENT_CLASS(cdns3_log_ctrl, 173 TP_PROTO(struct usb_ctrlrequest *ctrl), 174 TP_ARGS(ctrl), 175 TP_STRUCT__entry( 176 __field(u8, bRequestType) 177 __field(u8, bRequest) 178 __field(u16, wValue) 179 __field(u16, wIndex) 180 __field(u16, wLength) 181 __dynamic_array(char, str, CDNS3_MSG_MAX) 182 ), 183 TP_fast_assign( 184 __entry->bRequestType = ctrl->bRequestType; 185 __entry->bRequest = ctrl->bRequest; 186 __entry->wValue = le16_to_cpu(ctrl->wValue); 187 __entry->wIndex = le16_to_cpu(ctrl->wIndex); 188 __entry->wLength = le16_to_cpu(ctrl->wLength); 189 ), 190 TP_printk("%s", usb_decode_ctrl(__get_str(str), CDNS3_MSG_MAX, 191 __entry->bRequestType, 192 __entry->bRequest, __entry->wValue, 193 __entry->wIndex, __entry->wLength) 194 ) 195 ); 196 197 DEFINE_EVENT(cdns3_log_ctrl, cdns3_ctrl_req, 198 TP_PROTO(struct usb_ctrlrequest *ctrl), 199 TP_ARGS(ctrl) 200 ); 201 202 DECLARE_EVENT_CLASS(cdns3_log_request, 203 TP_PROTO(struct cdns3_request *req), 204 TP_ARGS(req), 205 TP_STRUCT__entry( 206 __string(name, req->priv_ep->name) 207 __field(struct cdns3_request *, req) 208 __field(void *, buf) 209 __field(unsigned int, actual) 210 __field(unsigned int, length) 211 __field(int, status) 212 __field(int, zero) 213 __field(int, short_not_ok) 214 __field(int, no_interrupt) 215 __field(int, start_trb) 216 __field(int, end_trb) 217 __field(int, flags) 218 __field(unsigned int, stream_id) 219 ), 220 TP_fast_assign( 221 __assign_str(name, req->priv_ep->name); 222 __entry->req = req; 223 __entry->buf = req->request.buf; 224 __entry->actual = req->request.actual; 225 __entry->length = req->request.length; 226 __entry->status = req->request.status; 227 __entry->zero = req->request.zero; 228 __entry->short_not_ok = req->request.short_not_ok; 229 __entry->no_interrupt = req->request.no_interrupt; 230 __entry->start_trb = req->start_trb; 231 __entry->end_trb = req->end_trb; 232 __entry->flags = req->flags; 233 __entry->stream_id = req->request.stream_id; 234 ), 235 TP_printk("%s: req: %p, req buff %p, length: %u/%u %s%s%s, status: %d," 236 " trb: [start:%d, end:%d], flags:%x SID: %u", 237 __get_str(name), __entry->req, __entry->buf, __entry->actual, 238 __entry->length, 239 __entry->zero ? "Z" : "z", 240 __entry->short_not_ok ? "S" : "s", 241 __entry->no_interrupt ? "I" : "i", 242 __entry->status, 243 __entry->start_trb, 244 __entry->end_trb, 245 __entry->flags, 246 __entry->stream_id 247 ) 248 ); 249 250 DEFINE_EVENT(cdns3_log_request, cdns3_alloc_request, 251 TP_PROTO(struct cdns3_request *req), 252 TP_ARGS(req) 253 ); 254 255 DEFINE_EVENT(cdns3_log_request, cdns3_free_request, 256 TP_PROTO(struct cdns3_request *req), 257 TP_ARGS(req) 258 ); 259 260 DEFINE_EVENT(cdns3_log_request, cdns3_ep_queue, 261 TP_PROTO(struct cdns3_request *req), 262 TP_ARGS(req) 263 ); 264 265 DEFINE_EVENT(cdns3_log_request, cdns3_ep_dequeue, 266 TP_PROTO(struct cdns3_request *req), 267 TP_ARGS(req) 268 ); 269 270 DEFINE_EVENT(cdns3_log_request, cdns3_gadget_giveback, 271 TP_PROTO(struct cdns3_request *req), 272 TP_ARGS(req) 273 ); 274 275 TRACE_EVENT(cdns3_ep0_queue, 276 TP_PROTO(struct cdns3_device *dev_priv, struct usb_request *request), 277 TP_ARGS(dev_priv, request), 278 TP_STRUCT__entry( 279 __field(int, dir) 280 __field(int, length) 281 ), 282 TP_fast_assign( 283 __entry->dir = dev_priv->ep0_data_dir; 284 __entry->length = request->length; 285 ), 286 TP_printk("Queue to ep0%s length: %u", __entry->dir ? "in" : "out", 287 __entry->length) 288 ); 289 290 DECLARE_EVENT_CLASS(cdns3_stream_split_transfer_len, 291 TP_PROTO(struct cdns3_request *req), 292 TP_ARGS(req), 293 TP_STRUCT__entry( 294 __string(name, req->priv_ep->name) 295 __field(struct cdns3_request *, req) 296 __field(unsigned int, length) 297 __field(unsigned int, actual) 298 __field(unsigned int, stream_id) 299 ), 300 TP_fast_assign( 301 __assign_str(name, req->priv_ep->name); 302 __entry->req = req; 303 __entry->actual = req->request.length; 304 __entry->length = req->request.actual; 305 __entry->stream_id = req->request.stream_id; 306 ), 307 TP_printk("%s: req: %p,request length: %u actual length: %u SID: %u", 308 __get_str(name), __entry->req, __entry->length, 309 __entry->actual, __entry->stream_id) 310 ); 311 312 DEFINE_EVENT(cdns3_stream_split_transfer_len, cdns3_stream_transfer_split, 313 TP_PROTO(struct cdns3_request *req), 314 TP_ARGS(req) 315 ); 316 317 DEFINE_EVENT(cdns3_stream_split_transfer_len, 318 cdns3_stream_transfer_split_next_part, 319 TP_PROTO(struct cdns3_request *req), 320 TP_ARGS(req) 321 ); 322 323 DECLARE_EVENT_CLASS(cdns3_log_aligned_request, 324 TP_PROTO(struct cdns3_request *priv_req), 325 TP_ARGS(priv_req), 326 TP_STRUCT__entry( 327 __string(name, priv_req->priv_ep->name) 328 __field(struct usb_request *, req) 329 __field(void *, buf) 330 __field(dma_addr_t, dma) 331 __field(void *, aligned_buf) 332 __field(dma_addr_t, aligned_dma) 333 __field(u32, aligned_buf_size) 334 ), 335 TP_fast_assign( 336 __assign_str(name, priv_req->priv_ep->name); 337 __entry->req = &priv_req->request; 338 __entry->buf = priv_req->request.buf; 339 __entry->dma = priv_req->request.dma; 340 __entry->aligned_buf = priv_req->aligned_buf->buf; 341 __entry->aligned_dma = priv_req->aligned_buf->dma; 342 __entry->aligned_buf_size = priv_req->aligned_buf->size; 343 ), 344 TP_printk("%s: req: %p, req buf %p, dma %pad a_buf %p a_dma %pad, size %d", 345 __get_str(name), __entry->req, __entry->buf, &__entry->dma, 346 __entry->aligned_buf, &__entry->aligned_dma, 347 __entry->aligned_buf_size 348 ) 349 ); 350 351 DEFINE_EVENT(cdns3_log_aligned_request, cdns3_free_aligned_request, 352 TP_PROTO(struct cdns3_request *req), 353 TP_ARGS(req) 354 ); 355 356 DEFINE_EVENT(cdns3_log_aligned_request, cdns3_prepare_aligned_request, 357 TP_PROTO(struct cdns3_request *req), 358 TP_ARGS(req) 359 ); 360 361 DECLARE_EVENT_CLASS(cdns3_log_map_request, 362 TP_PROTO(struct cdns3_request *priv_req), 363 TP_ARGS(priv_req), 364 TP_STRUCT__entry( 365 __string(name, priv_req->priv_ep->name) 366 __field(struct usb_request *, req) 367 __field(void *, buf) 368 __field(dma_addr_t, dma) 369 ), 370 TP_fast_assign( 371 __assign_str(name, priv_req->priv_ep->name); 372 __entry->req = &priv_req->request; 373 __entry->buf = priv_req->request.buf; 374 __entry->dma = priv_req->request.dma; 375 ), 376 TP_printk("%s: req: %p, req buf %p, dma %p", 377 __get_str(name), __entry->req, __entry->buf, &__entry->dma 378 ) 379 ); 380 DEFINE_EVENT(cdns3_log_map_request, cdns3_map_request, 381 TP_PROTO(struct cdns3_request *req), 382 TP_ARGS(req) 383 ); 384 DEFINE_EVENT(cdns3_log_map_request, cdns3_mapped_request, 385 TP_PROTO(struct cdns3_request *req), 386 TP_ARGS(req) 387 ); 388 389 DECLARE_EVENT_CLASS(cdns3_log_trb, 390 TP_PROTO(struct cdns3_endpoint *priv_ep, struct cdns3_trb *trb), 391 TP_ARGS(priv_ep, trb), 392 TP_STRUCT__entry( 393 __string(name, priv_ep->name) 394 __field(struct cdns3_trb *, trb) 395 __field(u32, buffer) 396 __field(u32, length) 397 __field(u32, control) 398 __field(u32, type) 399 __field(unsigned int, last_stream_id) 400 ), 401 TP_fast_assign( 402 __assign_str(name, priv_ep->name); 403 __entry->trb = trb; 404 __entry->buffer = le32_to_cpu(trb->buffer); 405 __entry->length = le32_to_cpu(trb->length); 406 __entry->control = le32_to_cpu(trb->control); 407 __entry->type = usb_endpoint_type(priv_ep->endpoint.desc); 408 __entry->last_stream_id = priv_ep->last_stream_id; 409 ), 410 TP_printk("%s: trb %p, dma buf: 0x%08x, size: %ld, burst: %d ctrl: 0x%08x (%s%s%s%s%s%s%s) SID:%lu LAST_SID:%u", 411 __get_str(name), __entry->trb, __entry->buffer, 412 TRB_LEN(__entry->length), 413 (u8)TRB_BURST_LEN_GET(__entry->length), 414 __entry->control, 415 __entry->control & TRB_CYCLE ? "C=1, " : "C=0, ", 416 __entry->control & TRB_TOGGLE ? "T=1, " : "T=0, ", 417 __entry->control & TRB_ISP ? "ISP, " : "", 418 __entry->control & TRB_FIFO_MODE ? "FIFO, " : "", 419 __entry->control & TRB_CHAIN ? "CHAIN, " : "", 420 __entry->control & TRB_IOC ? "IOC, " : "", 421 TRB_FIELD_TO_TYPE(__entry->control) == TRB_NORMAL ? "Normal" : "LINK", 422 TRB_FIELD_TO_STREAMID(__entry->control), 423 __entry->last_stream_id 424 ) 425 ); 426 427 DEFINE_EVENT(cdns3_log_trb, cdns3_prepare_trb, 428 TP_PROTO(struct cdns3_endpoint *priv_ep, struct cdns3_trb *trb), 429 TP_ARGS(priv_ep, trb) 430 ); 431 432 DEFINE_EVENT(cdns3_log_trb, cdns3_complete_trb, 433 TP_PROTO(struct cdns3_endpoint *priv_ep, struct cdns3_trb *trb), 434 TP_ARGS(priv_ep, trb) 435 ); 436 437 DECLARE_EVENT_CLASS(cdns3_log_ring, 438 TP_PROTO(struct cdns3_endpoint *priv_ep), 439 TP_ARGS(priv_ep), 440 TP_STRUCT__entry( 441 __dynamic_array(u8, ring, TRB_RING_SIZE) 442 __dynamic_array(u8, priv_ep, sizeof(struct cdns3_endpoint)) 443 __dynamic_array(char, buffer, 444 (TRBS_PER_SEGMENT * 65) + CDNS3_MSG_MAX) 445 ), 446 TP_fast_assign( 447 memcpy(__get_dynamic_array(priv_ep), priv_ep, 448 sizeof(struct cdns3_endpoint)); 449 memcpy(__get_dynamic_array(ring), priv_ep->trb_pool, 450 TRB_RING_SIZE); 451 ), 452 453 TP_printk("%s", 454 cdns3_dbg_ring((struct cdns3_endpoint *)__get_str(priv_ep), 455 (struct cdns3_trb *)__get_str(ring), 456 __get_str(buffer))) 457 ); 458 459 DEFINE_EVENT(cdns3_log_ring, cdns3_ring, 460 TP_PROTO(struct cdns3_endpoint *priv_ep), 461 TP_ARGS(priv_ep) 462 ); 463 464 DECLARE_EVENT_CLASS(cdns3_log_ep, 465 TP_PROTO(struct cdns3_endpoint *priv_ep), 466 TP_ARGS(priv_ep), 467 TP_STRUCT__entry( 468 __string(name, priv_ep->name) 469 __field(unsigned int, maxpacket) 470 __field(unsigned int, maxpacket_limit) 471 __field(unsigned int, max_streams) 472 __field(unsigned int, use_streams) 473 __field(unsigned int, maxburst) 474 __field(unsigned int, flags) 475 __field(unsigned int, dir) 476 __field(u8, enqueue) 477 __field(u8, dequeue) 478 ), 479 TP_fast_assign( 480 __assign_str(name, priv_ep->name); 481 __entry->maxpacket = priv_ep->endpoint.maxpacket; 482 __entry->maxpacket_limit = priv_ep->endpoint.maxpacket_limit; 483 __entry->max_streams = priv_ep->endpoint.max_streams; 484 __entry->use_streams = priv_ep->use_streams; 485 __entry->maxburst = priv_ep->endpoint.maxburst; 486 __entry->flags = priv_ep->flags; 487 __entry->dir = priv_ep->dir; 488 __entry->enqueue = priv_ep->enqueue; 489 __entry->dequeue = priv_ep->dequeue; 490 ), 491 TP_printk("%s: mps: %d/%d. streams: %d, stream enable: %d, burst: %d, " 492 "enq idx: %d, deq idx: %d, flags %s%s%s%s%s%s%s%s, dir: %s", 493 __get_str(name), __entry->maxpacket, 494 __entry->maxpacket_limit, __entry->max_streams, 495 __entry->use_streams, 496 __entry->maxburst, __entry->enqueue, 497 __entry->dequeue, 498 __entry->flags & EP_ENABLED ? "EN | " : "", 499 __entry->flags & EP_STALLED ? "STALLED | " : "", 500 __entry->flags & EP_WEDGE ? "WEDGE | " : "", 501 __entry->flags & EP_TRANSFER_STARTED ? "STARTED | " : "", 502 __entry->flags & EP_UPDATE_EP_TRBADDR ? "UPD TRB | " : "", 503 __entry->flags & EP_PENDING_REQUEST ? "REQ PEN | " : "", 504 __entry->flags & EP_RING_FULL ? "RING FULL |" : "", 505 __entry->flags & EP_CLAIMED ? "CLAIMED " : "", 506 __entry->dir ? "IN" : "OUT" 507 ) 508 ); 509 510 DEFINE_EVENT(cdns3_log_ep, cdns3_gadget_ep_enable, 511 TP_PROTO(struct cdns3_endpoint *priv_ep), 512 TP_ARGS(priv_ep) 513 ); 514 515 DEFINE_EVENT(cdns3_log_ep, cdns3_gadget_ep_disable, 516 TP_PROTO(struct cdns3_endpoint *priv_ep), 517 TP_ARGS(priv_ep) 518 ); 519 520 DECLARE_EVENT_CLASS(cdns3_log_request_handled, 521 TP_PROTO(struct cdns3_request *priv_req, int current_index, 522 int handled), 523 TP_ARGS(priv_req, current_index, handled), 524 TP_STRUCT__entry( 525 __field(struct cdns3_request *, priv_req) 526 __field(unsigned int, dma_position) 527 __field(unsigned int, handled) 528 __field(unsigned int, dequeue_idx) 529 __field(unsigned int, enqueue_idx) 530 __field(unsigned int, start_trb) 531 __field(unsigned int, end_trb) 532 ), 533 TP_fast_assign( 534 __entry->priv_req = priv_req; 535 __entry->dma_position = current_index; 536 __entry->handled = handled; 537 __entry->dequeue_idx = priv_req->priv_ep->dequeue; 538 __entry->enqueue_idx = priv_req->priv_ep->enqueue; 539 __entry->start_trb = priv_req->start_trb; 540 __entry->end_trb = priv_req->end_trb; 541 ), 542 TP_printk("Req: %p %s, DMA pos: %d, ep deq: %d, ep enq: %d," 543 " start trb: %d, end trb: %d", 544 __entry->priv_req, 545 __entry->handled ? "handled" : "not handled", 546 __entry->dma_position, __entry->dequeue_idx, 547 __entry->enqueue_idx, __entry->start_trb, 548 __entry->end_trb 549 ) 550 ); 551 552 DEFINE_EVENT(cdns3_log_request_handled, cdns3_request_handled, 553 TP_PROTO(struct cdns3_request *priv_req, int current_index, 554 int handled), 555 TP_ARGS(priv_req, current_index, handled) 556 ); 557 #endif /* __LINUX_CDNS3_TRACE */ 558 559 /* this part must be outside header guard */ 560 561 #undef TRACE_INCLUDE_PATH 562 #define TRACE_INCLUDE_PATH . 563 564 #undef TRACE_INCLUDE_FILE 565 #define TRACE_INCLUDE_FILE cdns3-trace 566 567 #include <trace/define_trace.h> 568