1 /* SPDX-License-Identifier: GPL-2.0 */
3 * USBSS device controller driver.
4 * Trace support header file.
6 * Copyright (C) 2018-2019 Cadence.
8 * Author: Pawel Laszczak <pawell@cadence.com>
12 #define TRACE_SYSTEM cdns3
14 #if !defined(__LINUX_CDNS3_TRACE) || defined(TRACE_HEADER_MULTI_READ)
15 #define __LINUX_CDNS3_TRACE
17 #include <linux/types.h>
18 #include <linux/tracepoint.h>
19 #include <asm/byteorder.h>
20 #include <linux/usb/ch9.h>
22 #include "cdns3-gadget.h"
23 #include "cdns3-debug.h"
25 #define CDNS3_MSG_MAX 500
27 TRACE_EVENT(cdns3_halt
,
28 TP_PROTO(struct cdns3_endpoint
*ep_priv
, u8 halt
, u8 flush
),
29 TP_ARGS(ep_priv
, halt
, flush
),
31 __string(name
, ep_priv
->name
)
38 __entry
->flush
= flush
;
40 TP_printk("Halt %s for %s: %s", __entry
->flush
? " and flush" : "",
41 __get_str(name
), __entry
->halt
? "set" : "cleared")
44 TRACE_EVENT(cdns3_wa1
,
45 TP_PROTO(struct cdns3_endpoint
*ep_priv
, char *msg
),
46 TP_ARGS(ep_priv
, msg
),
48 __string(ep_name
, ep_priv
->name
)
52 __assign_str(ep_name
);
55 TP_printk("WA1: %s %s", __get_str(ep_name
), __get_str(msg
))
58 TRACE_EVENT(cdns3_wa2
,
59 TP_PROTO(struct cdns3_endpoint
*ep_priv
, char *msg
),
60 TP_ARGS(ep_priv
, msg
),
62 __string(ep_name
, ep_priv
->name
)
66 __assign_str(ep_name
);
69 TP_printk("WA2: %s %s", __get_str(ep_name
), __get_str(msg
))
72 DECLARE_EVENT_CLASS(cdns3_log_doorbell
,
73 TP_PROTO(const char *ep_name
, u32 ep_trbaddr
),
74 TP_ARGS(ep_name
, ep_trbaddr
),
76 __string(name
, ep_name
)
77 __field(u32
, ep_trbaddr
)
81 __entry
->ep_trbaddr
= ep_trbaddr
;
83 TP_printk("%s, ep_trbaddr %08x", __get_str(name
),
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
)
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
)
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
),
101 __field(enum usb_device_speed
, speed
)
102 __field(u32
, usb_ists
)
105 __entry
->speed
= cdns3_get_speed(priv_dev
);
106 __entry
->usb_ists
= usb_ists
;
108 TP_printk("%s", cdns3_decode_usb_irq(__get_buf(CDNS3_MSG_MAX
), __entry
->speed
,
112 DEFINE_EVENT(cdns3_log_usb_irq
, cdns3_usb_irq
,
113 TP_PROTO(struct cdns3_device
*priv_dev
, u32 usb_ists
),
114 TP_ARGS(priv_dev
, usb_ists
)
117 DECLARE_EVENT_CLASS(cdns3_log_epx_irq
,
118 TP_PROTO(struct cdns3_device
*priv_dev
, struct cdns3_endpoint
*priv_ep
),
119 TP_ARGS(priv_dev
, priv_ep
),
121 __string(ep_name
, priv_ep
->name
)
123 __field(u32
, ep_traddr
)
124 __field(u32
, ep_last_sid
)
125 __field(u32
, use_streams
)
128 __assign_str(ep_name
);
129 __entry
->ep_sts
= readl(&priv_dev
->regs
->ep_sts
);
130 __entry
->ep_traddr
= readl(&priv_dev
->regs
->ep_traddr
);
131 __entry
->ep_last_sid
= priv_ep
->last_stream_id
;
132 __entry
->use_streams
= priv_ep
->use_streams
;
134 TP_printk("%s, ep_traddr: %08x ep_last_sid: %08x use_streams: %d",
135 cdns3_decode_epx_irq(__get_buf(CDNS3_MSG_MAX
),
139 __entry
->ep_last_sid
,
140 __entry
->use_streams
)
143 DEFINE_EVENT(cdns3_log_epx_irq
, cdns3_epx_irq
,
144 TP_PROTO(struct cdns3_device
*priv_dev
, struct cdns3_endpoint
*priv_ep
),
145 TP_ARGS(priv_dev
, priv_ep
)
148 DECLARE_EVENT_CLASS(cdns3_log_ep0_irq
,
149 TP_PROTO(struct cdns3_device
*priv_dev
, u32 ep_sts
),
150 TP_ARGS(priv_dev
, ep_sts
),
156 __entry
->ep_dir
= priv_dev
->selected_ep
;
157 __entry
->ep_sts
= ep_sts
;
159 TP_printk("%s", cdns3_decode_ep0_irq(__get_buf(CDNS3_MSG_MAX
),
164 DEFINE_EVENT(cdns3_log_ep0_irq
, cdns3_ep0_irq
,
165 TP_PROTO(struct cdns3_device
*priv_dev
, u32 ep_sts
),
166 TP_ARGS(priv_dev
, ep_sts
)
169 DECLARE_EVENT_CLASS(cdns3_log_ctrl
,
170 TP_PROTO(struct usb_ctrlrequest
*ctrl
),
173 __field(u8
, bRequestType
)
174 __field(u8
, bRequest
)
177 __field(u16
, wLength
)
180 __entry
->bRequestType
= ctrl
->bRequestType
;
181 __entry
->bRequest
= ctrl
->bRequest
;
182 __entry
->wValue
= le16_to_cpu(ctrl
->wValue
);
183 __entry
->wIndex
= le16_to_cpu(ctrl
->wIndex
);
184 __entry
->wLength
= le16_to_cpu(ctrl
->wLength
);
186 TP_printk("%s", usb_decode_ctrl(__get_buf(CDNS3_MSG_MAX
), CDNS3_MSG_MAX
,
187 __entry
->bRequestType
,
188 __entry
->bRequest
, __entry
->wValue
,
189 __entry
->wIndex
, __entry
->wLength
)
193 DEFINE_EVENT(cdns3_log_ctrl
, cdns3_ctrl_req
,
194 TP_PROTO(struct usb_ctrlrequest
*ctrl
),
198 DECLARE_EVENT_CLASS(cdns3_log_request
,
199 TP_PROTO(struct cdns3_request
*req
),
202 __string(name
, req
->priv_ep
->name
)
203 __field(struct cdns3_request
*, req
)
205 __field(unsigned int, actual
)
206 __field(unsigned int, length
)
209 __field(int, short_not_ok
)
210 __field(int, no_interrupt
)
211 __field(int, start_trb
)
212 __field(int, end_trb
)
214 __field(unsigned int, stream_id
)
219 __entry
->buf
= req
->request
.buf
;
220 __entry
->actual
= req
->request
.actual
;
221 __entry
->length
= req
->request
.length
;
222 __entry
->status
= req
->request
.status
;
223 __entry
->zero
= req
->request
.zero
;
224 __entry
->short_not_ok
= req
->request
.short_not_ok
;
225 __entry
->no_interrupt
= req
->request
.no_interrupt
;
226 __entry
->start_trb
= req
->start_trb
;
227 __entry
->end_trb
= req
->end_trb
;
228 __entry
->flags
= req
->flags
;
229 __entry
->stream_id
= req
->request
.stream_id
;
231 TP_printk("%s: req: %p, req buff %p, length: %u/%u %s%s%s, status: %d,"
232 " trb: [start:%d, end:%d], flags:%x SID: %u",
233 __get_str(name
), __entry
->req
, __entry
->buf
, __entry
->actual
,
235 __entry
->zero
? "Z" : "z",
236 __entry
->short_not_ok
? "S" : "s",
237 __entry
->no_interrupt
? "I" : "i",
246 DEFINE_EVENT(cdns3_log_request
, cdns3_alloc_request
,
247 TP_PROTO(struct cdns3_request
*req
),
251 DEFINE_EVENT(cdns3_log_request
, cdns3_free_request
,
252 TP_PROTO(struct cdns3_request
*req
),
256 DEFINE_EVENT(cdns3_log_request
, cdns3_ep_queue
,
257 TP_PROTO(struct cdns3_request
*req
),
261 DEFINE_EVENT(cdns3_log_request
, cdns3_ep_dequeue
,
262 TP_PROTO(struct cdns3_request
*req
),
266 DEFINE_EVENT(cdns3_log_request
, cdns3_gadget_giveback
,
267 TP_PROTO(struct cdns3_request
*req
),
271 TRACE_EVENT(cdns3_ep0_queue
,
272 TP_PROTO(struct cdns3_device
*dev_priv
, struct usb_request
*request
),
273 TP_ARGS(dev_priv
, request
),
279 __entry
->dir
= dev_priv
->ep0_data_dir
;
280 __entry
->length
= request
->length
;
282 TP_printk("Queue to ep0%s length: %u", __entry
->dir
? "in" : "out",
286 DECLARE_EVENT_CLASS(cdns3_stream_split_transfer_len
,
287 TP_PROTO(struct cdns3_request
*req
),
290 __string(name
, req
->priv_ep
->name
)
291 __field(struct cdns3_request
*, req
)
292 __field(unsigned int, length
)
293 __field(unsigned int, actual
)
294 __field(unsigned int, stream_id
)
299 __entry
->actual
= req
->request
.length
;
300 __entry
->length
= req
->request
.actual
;
301 __entry
->stream_id
= req
->request
.stream_id
;
303 TP_printk("%s: req: %p,request length: %u actual length: %u SID: %u",
304 __get_str(name
), __entry
->req
, __entry
->length
,
305 __entry
->actual
, __entry
->stream_id
)
308 DEFINE_EVENT(cdns3_stream_split_transfer_len
, cdns3_stream_transfer_split
,
309 TP_PROTO(struct cdns3_request
*req
),
313 DEFINE_EVENT(cdns3_stream_split_transfer_len
,
314 cdns3_stream_transfer_split_next_part
,
315 TP_PROTO(struct cdns3_request
*req
),
319 DECLARE_EVENT_CLASS(cdns3_log_aligned_request
,
320 TP_PROTO(struct cdns3_request
*priv_req
),
323 __string(name
, priv_req
->priv_ep
->name
)
324 __field(struct usb_request
*, req
)
326 __field(dma_addr_t
, dma
)
327 __field(void *, aligned_buf
)
328 __field(dma_addr_t
, aligned_dma
)
329 __field(u32
, aligned_buf_size
)
333 __entry
->req
= &priv_req
->request
;
334 __entry
->buf
= priv_req
->request
.buf
;
335 __entry
->dma
= priv_req
->request
.dma
;
336 __entry
->aligned_buf
= priv_req
->aligned_buf
->buf
;
337 __entry
->aligned_dma
= priv_req
->aligned_buf
->dma
;
338 __entry
->aligned_buf_size
= priv_req
->aligned_buf
->size
;
340 TP_printk("%s: req: %p, req buf %p, dma %pad a_buf %p a_dma %pad, size %d",
341 __get_str(name
), __entry
->req
, __entry
->buf
, &__entry
->dma
,
342 __entry
->aligned_buf
, &__entry
->aligned_dma
,
343 __entry
->aligned_buf_size
347 DEFINE_EVENT(cdns3_log_aligned_request
, cdns3_free_aligned_request
,
348 TP_PROTO(struct cdns3_request
*req
),
352 DEFINE_EVENT(cdns3_log_aligned_request
, cdns3_prepare_aligned_request
,
353 TP_PROTO(struct cdns3_request
*req
),
357 DECLARE_EVENT_CLASS(cdns3_log_map_request
,
358 TP_PROTO(struct cdns3_request
*priv_req
),
361 __string(name
, priv_req
->priv_ep
->name
)
362 __field(struct usb_request
*, req
)
364 __field(dma_addr_t
, dma
)
368 __entry
->req
= &priv_req
->request
;
369 __entry
->buf
= priv_req
->request
.buf
;
370 __entry
->dma
= priv_req
->request
.dma
;
372 TP_printk("%s: req: %p, req buf %p, dma %p",
373 __get_str(name
), __entry
->req
, __entry
->buf
, &__entry
->dma
376 DEFINE_EVENT(cdns3_log_map_request
, cdns3_map_request
,
377 TP_PROTO(struct cdns3_request
*req
),
380 DEFINE_EVENT(cdns3_log_map_request
, cdns3_mapped_request
,
381 TP_PROTO(struct cdns3_request
*req
),
385 DECLARE_EVENT_CLASS(cdns3_log_trb
,
386 TP_PROTO(struct cdns3_endpoint
*priv_ep
, struct cdns3_trb
*trb
),
387 TP_ARGS(priv_ep
, trb
),
389 __string(name
, priv_ep
->name
)
390 __field(struct cdns3_trb
*, trb
)
393 __field(u32
, control
)
395 __field(unsigned int, last_stream_id
)
400 __entry
->buffer
= le32_to_cpu(trb
->buffer
);
401 __entry
->length
= le32_to_cpu(trb
->length
);
402 __entry
->control
= le32_to_cpu(trb
->control
);
403 __entry
->type
= usb_endpoint_type(priv_ep
->endpoint
.desc
);
404 __entry
->last_stream_id
= priv_ep
->last_stream_id
;
406 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",
407 __get_str(name
), __entry
->trb
, __entry
->buffer
,
408 TRB_LEN(__entry
->length
),
409 (u8
)TRB_BURST_LEN_GET(__entry
->length
),
411 __entry
->control
& TRB_CYCLE
? "C=1, " : "C=0, ",
412 __entry
->control
& TRB_TOGGLE
? "T=1, " : "T=0, ",
413 __entry
->control
& TRB_ISP
? "ISP, " : "",
414 __entry
->control
& TRB_FIFO_MODE
? "FIFO, " : "",
415 __entry
->control
& TRB_CHAIN
? "CHAIN, " : "",
416 __entry
->control
& TRB_IOC
? "IOC, " : "",
417 TRB_FIELD_TO_TYPE(__entry
->control
) == TRB_NORMAL
? "Normal" : "LINK",
418 TRB_FIELD_TO_STREAMID(__entry
->control
),
419 __entry
->last_stream_id
423 DEFINE_EVENT(cdns3_log_trb
, cdns3_prepare_trb
,
424 TP_PROTO(struct cdns3_endpoint
*priv_ep
, struct cdns3_trb
*trb
),
425 TP_ARGS(priv_ep
, trb
)
428 DEFINE_EVENT(cdns3_log_trb
, cdns3_complete_trb
,
429 TP_PROTO(struct cdns3_endpoint
*priv_ep
, struct cdns3_trb
*trb
),
430 TP_ARGS(priv_ep
, trb
)
433 DECLARE_EVENT_CLASS(cdns3_log_ring
,
434 TP_PROTO(struct cdns3_endpoint
*priv_ep
),
437 __dynamic_array(char, buffer
,
438 GET_TRBS_PER_SEGMENT(priv_ep
->type
) > TRBS_PER_SEGMENT
?
440 (GET_TRBS_PER_SEGMENT(priv_ep
->type
) * 65) + CDNS3_MSG_MAX
)
443 cdns3_dbg_ring(priv_ep
, __get_str(buffer
));
446 TP_printk("%s", __get_str(buffer
))
449 DEFINE_EVENT(cdns3_log_ring
, cdns3_ring
,
450 TP_PROTO(struct cdns3_endpoint
*priv_ep
),
454 DECLARE_EVENT_CLASS(cdns3_log_ep
,
455 TP_PROTO(struct cdns3_endpoint
*priv_ep
),
458 __string(name
, priv_ep
->name
)
459 __field(unsigned int, maxpacket
)
460 __field(unsigned int, maxpacket_limit
)
461 __field(unsigned int, max_streams
)
462 __field(unsigned int, use_streams
)
463 __field(unsigned int, maxburst
)
464 __field(unsigned int, flags
)
465 __field(unsigned int, dir
)
471 __entry
->maxpacket
= priv_ep
->endpoint
.maxpacket
;
472 __entry
->maxpacket_limit
= priv_ep
->endpoint
.maxpacket_limit
;
473 __entry
->max_streams
= priv_ep
->endpoint
.max_streams
;
474 __entry
->use_streams
= priv_ep
->use_streams
;
475 __entry
->maxburst
= priv_ep
->endpoint
.maxburst
;
476 __entry
->flags
= priv_ep
->flags
;
477 __entry
->dir
= priv_ep
->dir
;
478 __entry
->enqueue
= priv_ep
->enqueue
;
479 __entry
->dequeue
= priv_ep
->dequeue
;
481 TP_printk("%s: mps: %d/%d. streams: %d, stream enable: %d, burst: %d, "
482 "enq idx: %d, deq idx: %d, flags %s%s%s%s%s%s%s%s, dir: %s",
483 __get_str(name
), __entry
->maxpacket
,
484 __entry
->maxpacket_limit
, __entry
->max_streams
,
485 __entry
->use_streams
,
486 __entry
->maxburst
, __entry
->enqueue
,
488 __entry
->flags
& EP_ENABLED
? "EN | " : "",
489 __entry
->flags
& EP_STALLED
? "STALLED | " : "",
490 __entry
->flags
& EP_WEDGE
? "WEDGE | " : "",
491 __entry
->flags
& EP_TRANSFER_STARTED
? "STARTED | " : "",
492 __entry
->flags
& EP_UPDATE_EP_TRBADDR
? "UPD TRB | " : "",
493 __entry
->flags
& EP_PENDING_REQUEST
? "REQ PEN | " : "",
494 __entry
->flags
& EP_RING_FULL
? "RING FULL |" : "",
495 __entry
->flags
& EP_CLAIMED
? "CLAIMED " : "",
496 __entry
->dir
? "IN" : "OUT"
500 DEFINE_EVENT(cdns3_log_ep
, cdns3_gadget_ep_enable
,
501 TP_PROTO(struct cdns3_endpoint
*priv_ep
),
505 DEFINE_EVENT(cdns3_log_ep
, cdns3_gadget_ep_disable
,
506 TP_PROTO(struct cdns3_endpoint
*priv_ep
),
510 DECLARE_EVENT_CLASS(cdns3_log_request_handled
,
511 TP_PROTO(struct cdns3_request
*priv_req
, int current_index
,
513 TP_ARGS(priv_req
, current_index
, handled
),
515 __field(struct cdns3_request
*, priv_req
)
516 __field(unsigned int, dma_position
)
517 __field(unsigned int, handled
)
518 __field(unsigned int, dequeue_idx
)
519 __field(unsigned int, enqueue_idx
)
520 __field(unsigned int, start_trb
)
521 __field(unsigned int, end_trb
)
524 __entry
->priv_req
= priv_req
;
525 __entry
->dma_position
= current_index
;
526 __entry
->handled
= handled
;
527 __entry
->dequeue_idx
= priv_req
->priv_ep
->dequeue
;
528 __entry
->enqueue_idx
= priv_req
->priv_ep
->enqueue
;
529 __entry
->start_trb
= priv_req
->start_trb
;
530 __entry
->end_trb
= priv_req
->end_trb
;
532 TP_printk("Req: %p %s, DMA pos: %d, ep deq: %d, ep enq: %d,"
533 " start trb: %d, end trb: %d",
535 __entry
->handled
? "handled" : "not handled",
536 __entry
->dma_position
, __entry
->dequeue_idx
,
537 __entry
->enqueue_idx
, __entry
->start_trb
,
542 DEFINE_EVENT(cdns3_log_request_handled
, cdns3_request_handled
,
543 TP_PROTO(struct cdns3_request
*priv_req
, int current_index
,
545 TP_ARGS(priv_req
, current_index
, handled
)
547 #endif /* __LINUX_CDNS3_TRACE */
549 /* this part must be outside header guard */
551 #undef TRACE_INCLUDE_PATH
552 #define TRACE_INCLUDE_PATH .
554 #undef TRACE_INCLUDE_FILE
555 #define TRACE_INCLUDE_FILE cdns3-trace
557 #include <trace/define_trace.h>