1 /* SPDX-License-Identifier: GPL-2.0 */
3 * USBHS-DEV device controller driver.
4 * Trace support header file.
6 * Copyright (C) 2023 Cadence.
8 * Author: Pawel Laszczak <pawell@cadence.com>
12 #define TRACE_SYSTEM cdns2-dev
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 cdns2_dev
21 #if !defined(__LINUX_CDNS2_TRACE) || defined(TRACE_HEADER_MULTI_READ)
22 #define __LINUX_CDNS2_TRACE
24 #include <linux/types.h>
25 #include <linux/tracepoint.h>
26 #include <asm/byteorder.h>
27 #include <linux/usb/ch9.h>
28 #include "cdns2-gadget.h"
29 #include "cdns2-debug.h"
31 #define CDNS2_MSG_MAX 500
33 DECLARE_EVENT_CLASS(cdns2_log_enable_disable,
42 TP_printk("%s", __entry->set ? "enabled" : "disabled")
45 DEFINE_EVENT(cdns2_log_enable_disable, cdns2_pullup,
50 DEFINE_EVENT(cdns2_log_enable_disable, cdns2_lpm,
55 DEFINE_EVENT(cdns2_log_enable_disable, cdns2_may_wakeup,
60 DECLARE_EVENT_CLASS(cdns2_log_simple,
67 __assign_str(text, msg);
69 TP_printk("%s", __get_str(text))
72 DEFINE_EVENT(cdns2_log_simple, cdns2_no_room_on_ring,
77 DEFINE_EVENT(cdns2_log_simple, cdns2_ep0_status_stage,
82 DEFINE_EVENT(cdns2_log_simple, cdns2_ep0_set_config,
87 DEFINE_EVENT(cdns2_log_simple, cdns2_ep0_setup,
92 DEFINE_EVENT(cdns2_log_simple, cdns2_device_state,
97 TRACE_EVENT(cdns2_ep_halt,
98 TP_PROTO(struct cdns2_endpoint *ep_priv, u8 halt, u8 flush),
99 TP_ARGS(ep_priv, halt, flush),
101 __string(name, ep_priv->name)
106 __assign_str(name, ep_priv->name);
107 __entry->halt = halt;
108 __entry->flush = flush;
110 TP_printk("Halt %s for %s: %s", __entry->flush ? " and flush" : "",
111 __get_str(name), __entry->halt ? "set" : "cleared")
114 TRACE_EVENT(cdns2_wa1,
115 TP_PROTO(struct cdns2_endpoint *ep_priv, char *msg),
116 TP_ARGS(ep_priv, msg),
118 __string(ep_name, ep_priv->name)
122 __assign_str(ep_name, ep_priv->name);
123 __assign_str(msg, msg);
125 TP_printk("WA1: %s %s", __get_str(ep_name), __get_str(msg))
128 DECLARE_EVENT_CLASS(cdns2_log_doorbell,
129 TP_PROTO(struct cdns2_endpoint *pep, u32 ep_trbaddr),
130 TP_ARGS(pep, ep_trbaddr),
132 __string(name, pep->num ? pep->name :
133 (pep->dir ? "ep0in" : "ep0out"))
134 __field(u32, ep_trbaddr)
137 __assign_str(name, pep->name);
138 __entry->ep_trbaddr = ep_trbaddr;
140 TP_printk("%s, ep_trbaddr %08x", __get_str(name),
144 DEFINE_EVENT(cdns2_log_doorbell, cdns2_doorbell_ep0,
145 TP_PROTO(struct cdns2_endpoint *pep, u32 ep_trbaddr),
146 TP_ARGS(pep, ep_trbaddr)
149 DEFINE_EVENT(cdns2_log_doorbell, cdns2_doorbell_epx,
150 TP_PROTO(struct cdns2_endpoint *pep, u32 ep_trbaddr),
151 TP_ARGS(pep, ep_trbaddr)
154 DECLARE_EVENT_CLASS(cdns2_log_usb_irq,
155 TP_PROTO(u32 usb_irq, u32 ext_irq),
156 TP_ARGS(usb_irq, ext_irq),
158 __field(u32, usb_irq)
159 __field(u32, ext_irq)
162 __entry->usb_irq = usb_irq;
163 __entry->ext_irq = ext_irq;
165 TP_printk("%s", cdns2_decode_usb_irq(__get_buf(CDNS2_MSG_MAX),
171 DEFINE_EVENT(cdns2_log_usb_irq, cdns2_usb_irq,
172 TP_PROTO(u32 usb_irq, u32 ext_irq),
173 TP_ARGS(usb_irq, ext_irq)
176 TRACE_EVENT(cdns2_dma_ep_ists,
177 TP_PROTO(u32 dma_ep_ists),
178 TP_ARGS(dma_ep_ists),
180 __field(u32, dma_ep_ists)
183 __entry->dma_ep_ists = dma_ep_ists;
185 TP_printk("OUT: 0x%04x, IN: 0x%04x", (u16)__entry->dma_ep_ists,
186 __entry->dma_ep_ists >> 16)
189 DECLARE_EVENT_CLASS(cdns2_log_epx_irq,
190 TP_PROTO(struct cdns2_device *pdev, struct cdns2_endpoint *pep),
193 __string(ep_name, pep->name)
195 __field(u32, ep_ists)
196 __field(u32, ep_traddr)
199 __assign_str(ep_name, pep->name);
200 __entry->ep_sts = readl(&pdev->adma_regs->ep_sts);
201 __entry->ep_ists = readl(&pdev->adma_regs->ep_ists);
202 __entry->ep_traddr = readl(&pdev->adma_regs->ep_traddr);
204 TP_printk("%s, ep_traddr: %08x",
205 cdns2_decode_epx_irq(__get_buf(CDNS2_MSG_MAX), CDNS2_MSG_MAX,
207 __entry->ep_ists, __entry->ep_sts),
211 DEFINE_EVENT(cdns2_log_epx_irq, cdns2_epx_irq,
212 TP_PROTO(struct cdns2_device *pdev, struct cdns2_endpoint *pep),
216 DECLARE_EVENT_CLASS(cdns2_log_ep0_irq,
217 TP_PROTO(struct cdns2_device *pdev),
221 __field(u32, ep_ists)
225 __entry->ep_dir = pdev->selected_ep;
226 __entry->ep_ists = readl(&pdev->adma_regs->ep_ists);
227 __entry->ep_sts = readl(&pdev->adma_regs->ep_sts);
229 TP_printk("%s", cdns2_decode_ep0_irq(__get_buf(CDNS2_MSG_MAX),
231 __entry->ep_ists, __entry->ep_sts,
235 DEFINE_EVENT(cdns2_log_ep0_irq, cdns2_ep0_irq,
236 TP_PROTO(struct cdns2_device *pdev),
240 DECLARE_EVENT_CLASS(cdns2_log_ctrl,
241 TP_PROTO(struct usb_ctrlrequest *ctrl),
244 __field(u8, bRequestType)
245 __field(u8, bRequest)
248 __field(u16, wLength)
251 __entry->bRequestType = ctrl->bRequestType;
252 __entry->bRequest = ctrl->bRequest;
253 __entry->wValue = le16_to_cpu(ctrl->wValue);
254 __entry->wIndex = le16_to_cpu(ctrl->wIndex);
255 __entry->wLength = le16_to_cpu(ctrl->wLength);
257 TP_printk("%s", usb_decode_ctrl(__get_buf(CDNS2_MSG_MAX), CDNS2_MSG_MAX,
258 __entry->bRequestType,
259 __entry->bRequest, __entry->wValue,
260 __entry->wIndex, __entry->wLength)
264 DEFINE_EVENT(cdns2_log_ctrl, cdns2_ctrl_req,
265 TP_PROTO(struct usb_ctrlrequest *ctrl),
269 DECLARE_EVENT_CLASS(cdns2_log_request,
270 TP_PROTO(struct cdns2_request *preq),
273 __string(name, preq->pep->name)
274 __field(struct usb_request *, request)
275 __field(struct cdns2_request *, preq)
277 __field(unsigned int, actual)
278 __field(unsigned int, length)
280 __field(dma_addr_t, dma)
282 __field(int, short_not_ok)
283 __field(int, no_interrupt)
284 __field(struct scatterlist*, sg)
285 __field(unsigned int, num_sgs)
286 __field(unsigned int, num_mapped_sgs)
287 __field(int, start_trb)
288 __field(int, end_trb)
291 __assign_str(name, preq->pep->name);
292 __entry->request = &preq->request;
293 __entry->preq = preq;
294 __entry->buf = preq->request.buf;
295 __entry->actual = preq->request.actual;
296 __entry->length = preq->request.length;
297 __entry->status = preq->request.status;
298 __entry->dma = preq->request.dma;
299 __entry->zero = preq->request.zero;
300 __entry->short_not_ok = preq->request.short_not_ok;
301 __entry->no_interrupt = preq->request.no_interrupt;
302 __entry->sg = preq->request.sg;
303 __entry->num_sgs = preq->request.num_sgs;
304 __entry->num_mapped_sgs = preq->request.num_mapped_sgs;
305 __entry->start_trb = preq->start_trb;
306 __entry->end_trb = preq->end_trb;
308 TP_printk("%s: req: %p, preq: %p, req buf: %p, length: %u/%u, status: %d,"
309 "buf dma: (%pad), %s%s%s, sg: %p, num_sgs: %d, num_m_sgs: %d,"
310 "trb: [start: %d, end: %d]",
311 __get_str(name), __entry->request, __entry->preq,
312 __entry->buf, __entry->actual, __entry->length,
313 __entry->status, &__entry->dma,
314 __entry->zero ? "Z" : "z",
315 __entry->short_not_ok ? "S" : "s",
316 __entry->no_interrupt ? "I" : "i",
317 __entry->sg, __entry->num_sgs, __entry->num_mapped_sgs,
323 DEFINE_EVENT(cdns2_log_request, cdns2_request_enqueue,
324 TP_PROTO(struct cdns2_request *preq),
328 DEFINE_EVENT(cdns2_log_request, cdns2_request_enqueue_error,
329 TP_PROTO(struct cdns2_request *preq),
333 DEFINE_EVENT(cdns2_log_request, cdns2_alloc_request,
334 TP_PROTO(struct cdns2_request *preq),
338 DEFINE_EVENT(cdns2_log_request, cdns2_free_request,
339 TP_PROTO(struct cdns2_request *preq),
343 DEFINE_EVENT(cdns2_log_request, cdns2_ep_queue,
344 TP_PROTO(struct cdns2_request *preq),
348 DEFINE_EVENT(cdns2_log_request, cdns2_request_dequeue,
349 TP_PROTO(struct cdns2_request *preq),
353 DEFINE_EVENT(cdns2_log_request, cdns2_request_giveback,
354 TP_PROTO(struct cdns2_request *preq),
358 TRACE_EVENT(cdns2_ep0_enqueue,
359 TP_PROTO(struct cdns2_device *dev_priv, struct usb_request *request),
360 TP_ARGS(dev_priv, request),
366 __entry->dir = dev_priv->eps[0].dir;
367 __entry->length = request->length;
369 TP_printk("Queue to ep0%s length: %u", __entry->dir ? "in" : "out",
373 DECLARE_EVENT_CLASS(cdns2_log_map_request,
374 TP_PROTO(struct cdns2_request *priv_req),
377 __string(name, priv_req->pep->name)
378 __field(struct usb_request *, req)
380 __field(dma_addr_t, dma)
383 __assign_str(name, priv_req->pep->name);
384 __entry->req = &priv_req->request;
385 __entry->buf = priv_req->request.buf;
386 __entry->dma = priv_req->request.dma;
388 TP_printk("%s: req: %p, req buf %p, dma %p",
389 __get_str(name), __entry->req, __entry->buf, &__entry->dma
393 DEFINE_EVENT(cdns2_log_map_request, cdns2_map_request,
394 TP_PROTO(struct cdns2_request *req),
397 DEFINE_EVENT(cdns2_log_map_request, cdns2_mapped_request,
398 TP_PROTO(struct cdns2_request *req),
402 DECLARE_EVENT_CLASS(cdns2_log_trb,
403 TP_PROTO(struct cdns2_endpoint *pep, struct cdns2_trb *trb),
406 __string(name, pep->name)
407 __field(struct cdns2_trb *, trb)
410 __field(u32, control)
414 __assign_str(name, pep->name);
416 __entry->buffer = le32_to_cpu(trb->buffer);
417 __entry->length = le32_to_cpu(trb->length);
418 __entry->control = le32_to_cpu(trb->control);
419 __entry->type = usb_endpoint_type(pep->endpoint.desc);
421 TP_printk("%s: trb V: %p, dma buf: P: 0x%08x, %s",
422 __get_str(name), __entry->trb, __entry->buffer,
423 cdns2_decode_trb(__get_buf(CDNS2_MSG_MAX), CDNS2_MSG_MAX,
424 __entry->control, __entry->length,
428 DEFINE_EVENT(cdns2_log_trb, cdns2_queue_trb,
429 TP_PROTO(struct cdns2_endpoint *pep, struct cdns2_trb *trb),
433 DEFINE_EVENT(cdns2_log_trb, cdns2_complete_trb,
434 TP_PROTO(struct cdns2_endpoint *pep, struct cdns2_trb *trb),
438 DECLARE_EVENT_CLASS(cdns2_log_ring,
439 TP_PROTO(struct cdns2_endpoint *pep),
442 __dynamic_array(u8, tr_seg, TR_SEG_SIZE)
443 __dynamic_array(u8, pep, sizeof(struct cdns2_endpoint))
444 __dynamic_array(char, buffer,
445 (TRBS_PER_SEGMENT * 65) + CDNS2_MSG_MAX)
448 memcpy(__get_dynamic_array(pep), pep,
449 sizeof(struct cdns2_endpoint));
450 memcpy(__get_dynamic_array(tr_seg), pep->ring.trbs,
455 cdns2_raw_ring((struct cdns2_endpoint *)__get_str(pep),
456 (struct cdns2_trb *)__get_str(tr_seg),
458 (TRBS_PER_SEGMENT * 65) + CDNS2_MSG_MAX))
461 DEFINE_EVENT(cdns2_log_ring, cdns2_ring,
462 TP_PROTO(struct cdns2_endpoint *pep),
466 DECLARE_EVENT_CLASS(cdns2_log_ep,
467 TP_PROTO(struct cdns2_endpoint *pep),
470 __string(name, pep->name)
471 __field(unsigned int, maxpacket)
472 __field(unsigned int, maxpacket_limit)
473 __field(unsigned int, flags)
474 __field(unsigned int, dir)
479 __assign_str(name, pep->name);
480 __entry->maxpacket = pep->endpoint.maxpacket;
481 __entry->maxpacket_limit = pep->endpoint.maxpacket_limit;
482 __entry->flags = pep->ep_state;
483 __entry->dir = pep->dir;
484 __entry->enqueue = pep->ring.enqueue;
485 __entry->dequeue = pep->ring.dequeue;
487 TP_printk("%s: mps: %d/%d, enq idx: %d, deq idx: %d, "
488 "flags: %s%s%s%s, dir: %s",
489 __get_str(name), __entry->maxpacket,
490 __entry->maxpacket_limit, __entry->enqueue,
492 __entry->flags & EP_ENABLED ? "EN | " : "",
493 __entry->flags & EP_STALLED ? "STALLED | " : "",
494 __entry->flags & EP_WEDGE ? "WEDGE | " : "",
495 __entry->flags & EP_RING_FULL ? "RING FULL |" : "",
496 __entry->dir ? "IN" : "OUT"
500 DEFINE_EVENT(cdns2_log_ep, cdns2_gadget_ep_enable,
501 TP_PROTO(struct cdns2_endpoint *pep),
505 DEFINE_EVENT(cdns2_log_ep, cdns2_gadget_ep_disable,
506 TP_PROTO(struct cdns2_endpoint *pep),
510 DEFINE_EVENT(cdns2_log_ep, cdns2_iso_out_ep_disable,
511 TP_PROTO(struct cdns2_endpoint *pep),
515 DEFINE_EVENT(cdns2_log_ep, cdns2_ep_busy_try_halt_again,
516 TP_PROTO(struct cdns2_endpoint *pep),
520 DECLARE_EVENT_CLASS(cdns2_log_request_handled,
521 TP_PROTO(struct cdns2_request *priv_req, int current_index,
523 TP_ARGS(priv_req, current_index, handled),
525 __field(struct cdns2_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)
534 __entry->priv_req = priv_req;
535 __entry->dma_position = current_index;
536 __entry->handled = handled;
537 __entry->dequeue_idx = priv_req->pep->ring.dequeue;
538 __entry->enqueue_idx = priv_req->pep->ring.enqueue;
539 __entry->start_trb = priv_req->start_trb;
540 __entry->end_trb = priv_req->end_trb;
542 TP_printk("Req: %p %s, DMA pos: %d, ep deq: %d, ep enq: %d,"
543 " start trb: %d, end trb: %d",
545 __entry->handled ? "handled" : "not handled",
546 __entry->dma_position, __entry->dequeue_idx,
547 __entry->enqueue_idx, __entry->start_trb,
552 DEFINE_EVENT(cdns2_log_request_handled, cdns2_request_handled,
553 TP_PROTO(struct cdns2_request *priv_req, int current_index,
555 TP_ARGS(priv_req, current_index, handled)
558 DECLARE_EVENT_CLASS(cdns2_log_epx_reg_config,
559 TP_PROTO(struct cdns2_device *pdev, struct cdns2_endpoint *pep),
562 __string(ep_name, pep->name)
563 __field(u8, burst_size)
564 __field(__le16, maxpack_reg)
565 __field(__u8, con_reg)
566 __field(u32, ep_sel_reg)
567 __field(u32, ep_sts_en_reg)
568 __field(u32, ep_cfg_reg)
571 __assign_str(ep_name, pep->name);
572 __entry->burst_size = pep->trb_burst_size;
573 __entry->maxpack_reg = pep->dir ? readw(&pdev->epx_regs->txmaxpack[pep->num - 1]) :
574 readw(&pdev->epx_regs->rxmaxpack[pep->num - 1]);
575 __entry->con_reg = pep->dir ? readb(&pdev->epx_regs->ep[pep->num - 1].txcon) :
576 readb(&pdev->epx_regs->ep[pep->num - 1].rxcon);
577 __entry->ep_sel_reg = readl(&pdev->adma_regs->ep_sel);
578 __entry->ep_sts_en_reg = readl(&pdev->adma_regs->ep_sts_en);
579 __entry->ep_cfg_reg = readl(&pdev->adma_regs->ep_cfg);
582 TP_printk("%s, maxpack: %d, con: %02x, dma_ep_sel: %08x, dma_ep_sts_en: %08x"
584 __get_str(ep_name), __entry->maxpack_reg, __entry->con_reg,
585 __entry->ep_sel_reg, __entry->ep_sts_en_reg,
590 DEFINE_EVENT(cdns2_log_epx_reg_config, cdns2_epx_hw_cfg,
591 TP_PROTO(struct cdns2_device *pdev, struct cdns2_endpoint *pep),
595 #endif /* __LINUX_CDNS2_TRACE */
597 /* This part must be outside header guard. */
599 #undef TRACE_INCLUDE_PATH
600 #define TRACE_INCLUDE_PATH .
602 #undef TRACE_INCLUDE_FILE
603 #define TRACE_INCLUDE_FILE cdns2-trace
605 #include <trace/define_trace.h>