1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Cadence CDNSP DRD Driver.
5 * Copyright (C) 2020 Cadence.
7 * Author: Pawel Laszczak <pawell@cadence.com>
10 #ifndef __LINUX_CDNSP_DEBUG
11 #define __LINUX_CDNSP_DEBUG
13 static inline const char *cdnsp_trb_comp_code_string(u8 status
)
20 case COMP_DATA_BUFFER_ERROR
:
21 return "Data Buffer Error";
22 case COMP_BABBLE_DETECTED_ERROR
:
23 return "Babble Detected";
26 case COMP_RESOURCE_ERROR
:
27 return "Resource Error";
28 case COMP_NO_SLOTS_AVAILABLE_ERROR
:
29 return "No Slots Available Error";
30 case COMP_INVALID_STREAM_TYPE_ERROR
:
31 return "Invalid Stream Type Error";
32 case COMP_SLOT_NOT_ENABLED_ERROR
:
33 return "Slot Not Enabled Error";
34 case COMP_ENDPOINT_NOT_ENABLED_ERROR
:
35 return "Endpoint Not Enabled Error";
36 case COMP_SHORT_PACKET
:
37 return "Short Packet";
38 case COMP_RING_UNDERRUN
:
39 return "Ring Underrun";
40 case COMP_RING_OVERRUN
:
41 return "Ring Overrun";
42 case COMP_VF_EVENT_RING_FULL_ERROR
:
43 return "VF Event Ring Full Error";
44 case COMP_PARAMETER_ERROR
:
45 return "Parameter Error";
46 case COMP_CONTEXT_STATE_ERROR
:
47 return "Context State Error";
48 case COMP_EVENT_RING_FULL_ERROR
:
49 return "Event Ring Full Error";
50 case COMP_INCOMPATIBLE_DEVICE_ERROR
:
51 return "Incompatible Device Error";
52 case COMP_MISSED_SERVICE_ERROR
:
53 return "Missed Service Error";
54 case COMP_COMMAND_RING_STOPPED
:
55 return "Command Ring Stopped";
56 case COMP_COMMAND_ABORTED
:
57 return "Command Aborted";
60 case COMP_STOPPED_LENGTH_INVALID
:
61 return "Stopped - Length Invalid";
62 case COMP_STOPPED_SHORT_PACKET
:
63 return "Stopped - Short Packet";
64 case COMP_MAX_EXIT_LATENCY_TOO_LARGE_ERROR
:
65 return "Max Exit Latency Too Large Error";
66 case COMP_ISOCH_BUFFER_OVERRUN
:
67 return "Isoch Buffer Overrun";
68 case COMP_EVENT_LOST_ERROR
:
69 return "Event Lost Error";
70 case COMP_UNDEFINED_ERROR
:
71 return "Undefined Error";
72 case COMP_INVALID_STREAM_ID_ERROR
:
73 return "Invalid Stream ID Error";
79 static inline const char *cdnsp_trb_type_string(u8 type
)
89 return "Status Stage";
99 return "Enable Slot Command";
100 case TRB_DISABLE_SLOT
:
101 return "Disable Slot Command";
103 return "Address Device Command";
105 return "Configure Endpoint Command";
106 case TRB_EVAL_CONTEXT
:
107 return "Evaluate Context Command";
109 return "Reset Endpoint Command";
111 return "Stop Ring Command";
113 return "Set TR Dequeue Pointer Command";
115 return "Reset Device Command";
116 case TRB_FORCE_HEADER
:
117 return "Force Header Command";
119 return "No-Op Command";
121 return "Transfer Event";
123 return "Command Completion Event";
124 case TRB_PORT_STATUS
:
125 return "Port Status Change Event";
127 return "Device Controller Event";
128 case TRB_MFINDEX_WRAP
:
129 return "MFINDEX Wrap Event";
130 case TRB_ENDPOINT_NRDY
:
131 return "Endpoint Not ready";
132 case TRB_HALT_ENDPOINT
:
133 return "Halt Endpoint";
139 static inline const char *cdnsp_ring_type_string(enum cdnsp_ring_type type
)
161 static inline char *cdnsp_slot_state_string(u32 state
)
164 case SLOT_STATE_ENABLED
:
165 return "enabled/disabled";
166 case SLOT_STATE_DEFAULT
:
168 case SLOT_STATE_ADDRESSED
:
170 case SLOT_STATE_CONFIGURED
:
177 static inline const char *cdnsp_decode_trb(char *str
, size_t size
, u32 field0
,
178 u32 field1
, u32 field2
, u32 field3
)
180 int ep_id
= TRB_TO_EP_INDEX(field3
) - 1;
181 int type
= TRB_FIELD_TO_TYPE(field3
);
186 ep_num
= DIV_ROUND_UP(ep_id
, 2);
190 ret
= scnprintf(str
, size
,
191 "LINK %08x%08x intr %ld type '%s' flags %c:%c:%c:%c",
192 field1
, field0
, GET_INTR_TARGET(field2
),
193 cdnsp_trb_type_string(type
),
194 field3
& TRB_IOC
? 'I' : 'i',
195 field3
& TRB_CHAIN
? 'C' : 'c',
196 field3
& TRB_TC
? 'T' : 't',
197 field3
& TRB_CYCLE
? 'C' : 'c');
201 case TRB_PORT_STATUS
:
203 ret
= scnprintf(str
, size
,
204 "ep%d%s(%d) type '%s' TRB %08x%08x status '%s'"
205 " len %ld slot %ld flags %c:%c",
206 ep_num
, ep_id
% 2 ? "out" : "in",
207 TRB_TO_EP_INDEX(field3
),
208 cdnsp_trb_type_string(type
), field1
, field0
,
209 cdnsp_trb_comp_code_string(GET_COMP_CODE(field2
)),
210 EVENT_TRB_LEN(field2
), TRB_TO_SLOT_ID(field3
),
211 field3
& EVENT_DATA
? 'E' : 'e',
212 field3
& TRB_CYCLE
? 'C' : 'c');
214 case TRB_MFINDEX_WRAP
:
215 ret
= scnprintf(str
, size
, "%s: flags %c",
216 cdnsp_trb_type_string(type
),
217 field3
& TRB_CYCLE
? 'C' : 'c');
220 ret
= scnprintf(str
, size
,
221 "type '%s' bRequestType %02x bRequest %02x "
222 "wValue %02x%02x wIndex %02x%02x wLength %d "
223 "length %ld TD size %ld intr %ld Setup ID %ld "
225 cdnsp_trb_type_string(type
),
227 (field0
& 0xff00) >> 8,
228 (field0
& 0xff000000) >> 24,
229 (field0
& 0xff0000) >> 16,
230 (field1
& 0xff00) >> 8,
232 (field1
& 0xff000000) >> 16 |
233 (field1
& 0xff0000) >> 16,
234 TRB_LEN(field2
), GET_TD_SIZE(field2
),
235 GET_INTR_TARGET(field2
),
236 TRB_SETUPID_TO_TYPE(field3
),
237 field3
& TRB_IDT
? 'D' : 'd',
238 field3
& TRB_IOC
? 'I' : 'i',
239 field3
& TRB_CYCLE
? 'C' : 'c');
242 ret
= scnprintf(str
, size
,
243 "type '%s' Buffer %08x%08x length %ld TD size %ld "
244 "intr %ld flags %c:%c:%c:%c:%c:%c:%c",
245 cdnsp_trb_type_string(type
),
246 field1
, field0
, TRB_LEN(field2
),
248 GET_INTR_TARGET(field2
),
249 field3
& TRB_IDT
? 'D' : 'i',
250 field3
& TRB_IOC
? 'I' : 'i',
251 field3
& TRB_CHAIN
? 'C' : 'c',
252 field3
& TRB_NO_SNOOP
? 'S' : 's',
253 field3
& TRB_ISP
? 'I' : 'i',
254 field3
& TRB_ENT
? 'E' : 'e',
255 field3
& TRB_CYCLE
? 'C' : 'c');
258 ret
= scnprintf(str
, size
,
259 "Buffer %08x%08x length %ld TD size %ld intr"
260 "%ld type '%s' flags %c:%c:%c:%c",
261 field1
, field0
, TRB_LEN(field2
),
263 GET_INTR_TARGET(field2
),
264 cdnsp_trb_type_string(type
),
265 field3
& TRB_IOC
? 'I' : 'i',
266 field3
& TRB_CHAIN
? 'C' : 'c',
267 field3
& TRB_ENT
? 'E' : 'e',
268 field3
& TRB_CYCLE
? 'C' : 'c');
274 ret
= scnprintf(str
, size
,
275 "type '%s' Buffer %08x%08x length %ld "
276 "TD size %ld intr %ld "
277 "flags %c:%c:%c:%c:%c:%c:%c:%c:%c",
278 cdnsp_trb_type_string(type
),
279 field1
, field0
, TRB_LEN(field2
),
281 GET_INTR_TARGET(field2
),
282 field3
& TRB_BEI
? 'B' : 'b',
283 field3
& TRB_IDT
? 'T' : 't',
284 field3
& TRB_IOC
? 'I' : 'i',
285 field3
& TRB_CHAIN
? 'C' : 'c',
286 field3
& TRB_NO_SNOOP
? 'S' : 's',
287 field3
& TRB_ISP
? 'I' : 'i',
288 field3
& TRB_ENT
? 'E' : 'e',
289 field3
& TRB_CYCLE
? 'C' : 'c',
290 !(field3
& TRB_EVENT_INVALIDATE
) ? 'V' : 'v');
293 case TRB_ENABLE_SLOT
:
294 ret
= scnprintf(str
, size
, "%s: flags %c",
295 cdnsp_trb_type_string(type
),
296 field3
& TRB_CYCLE
? 'C' : 'c');
298 case TRB_DISABLE_SLOT
:
299 ret
= scnprintf(str
, size
, "%s: slot %ld flags %c",
300 cdnsp_trb_type_string(type
),
301 TRB_TO_SLOT_ID(field3
),
302 field3
& TRB_CYCLE
? 'C' : 'c');
305 ret
= scnprintf(str
, size
,
306 "%s: ctx %08x%08x slot %ld flags %c:%c",
307 cdnsp_trb_type_string(type
), field1
, field0
,
308 TRB_TO_SLOT_ID(field3
),
309 field3
& TRB_BSR
? 'B' : 'b',
310 field3
& TRB_CYCLE
? 'C' : 'c');
313 ret
= scnprintf(str
, size
,
314 "%s: ctx %08x%08x slot %ld flags %c:%c",
315 cdnsp_trb_type_string(type
), field1
, field0
,
316 TRB_TO_SLOT_ID(field3
),
317 field3
& TRB_DC
? 'D' : 'd',
318 field3
& TRB_CYCLE
? 'C' : 'c');
320 case TRB_EVAL_CONTEXT
:
321 ret
= scnprintf(str
, size
,
322 "%s: ctx %08x%08x slot %ld flags %c",
323 cdnsp_trb_type_string(type
), field1
, field0
,
324 TRB_TO_SLOT_ID(field3
),
325 field3
& TRB_CYCLE
? 'C' : 'c');
328 case TRB_HALT_ENDPOINT
:
329 ret
= scnprintf(str
, size
,
330 "%s: ep%d%s(%d) ctx %08x%08x slot %ld flags %c",
331 cdnsp_trb_type_string(type
),
332 ep_num
, ep_id
% 2 ? "out" : "in",
333 TRB_TO_EP_INDEX(field3
), field1
, field0
,
334 TRB_TO_SLOT_ID(field3
),
335 field3
& TRB_CYCLE
? 'C' : 'c');
338 ret
= scnprintf(str
, size
,
339 "%s: ep%d%s(%d) slot %ld sp %d flags %c",
340 cdnsp_trb_type_string(type
),
341 ep_num
, ep_id
% 2 ? "out" : "in",
342 TRB_TO_EP_INDEX(field3
),
343 TRB_TO_SLOT_ID(field3
),
344 TRB_TO_SUSPEND_PORT(field3
),
345 field3
& TRB_CYCLE
? 'C' : 'c');
348 ret
= scnprintf(str
, size
,
349 "%s: ep%d%s(%d) deq %08x%08x stream %ld slot %ld flags %c",
350 cdnsp_trb_type_string(type
),
351 ep_num
, ep_id
% 2 ? "out" : "in",
352 TRB_TO_EP_INDEX(field3
), field1
, field0
,
353 TRB_TO_STREAM_ID(field2
),
354 TRB_TO_SLOT_ID(field3
),
355 field3
& TRB_CYCLE
? 'C' : 'c');
358 ret
= scnprintf(str
, size
, "%s: slot %ld flags %c",
359 cdnsp_trb_type_string(type
),
360 TRB_TO_SLOT_ID(field3
),
361 field3
& TRB_CYCLE
? 'C' : 'c');
363 case TRB_ENDPOINT_NRDY
:
364 temp
= TRB_TO_HOST_STREAM(field2
);
366 ret
= scnprintf(str
, size
,
367 "%s: ep%d%s(%d) H_SID %x%s%s D_SID %lx flags %c:%c",
368 cdnsp_trb_type_string(type
),
369 ep_num
, ep_id
% 2 ? "out" : "in",
370 TRB_TO_EP_INDEX(field3
), temp
,
371 temp
== STREAM_PRIME_ACK
? "(PRIME)" : "",
372 temp
== STREAM_REJECTED
? "(REJECTED)" : "",
373 TRB_TO_DEV_STREAM(field0
),
374 field3
& TRB_STAT
? 'S' : 's',
375 field3
& TRB_CYCLE
? 'C' : 'c');
378 ret
= scnprintf(str
, size
,
379 "type '%s' -> raw %08x %08x %08x %08x",
380 cdnsp_trb_type_string(type
),
381 field0
, field1
, field2
, field3
);
385 pr_info("CDNSP: buffer may be truncated.\n");
390 static inline const char *cdnsp_decode_slot_context(u32 info
, u32 info2
,
391 u32 int_target
, u32 state
)
393 static char str
[1024];
398 speed
= info
& DEV_SPEED
;
411 s
= "super-speed plus";
417 ret
= sprintf(str
, "%s Ctx Entries %d",
418 s
, (info
& LAST_CTX_MASK
) >> 27);
420 ret
+= sprintf(str
+ ret
, " [Intr %ld] Addr %ld State %s",
421 GET_INTR_TARGET(int_target
), state
& DEV_ADDR_MASK
,
422 cdnsp_slot_state_string(GET_SLOT_STATE(state
)));
427 static inline const char *cdnsp_portsc_link_state_string(u32 portsc
)
429 switch (portsc
& PORT_PLS_MASK
) {
451 return "Compliance mode";
463 static inline const char *cdnsp_decode_portsc(char *str
, size_t size
,
468 ret
= scnprintf(str
, size
, "%s %s %s Link:%s PortSpeed:%d ",
469 portsc
& PORT_POWER
? "Powered" : "Powered-off",
470 portsc
& PORT_CONNECT
? "Connected" : "Not-connected",
471 portsc
& PORT_PED
? "Enabled" : "Disabled",
472 cdnsp_portsc_link_state_string(portsc
),
473 DEV_PORT_SPEED(portsc
));
475 if (portsc
& PORT_RESET
)
476 ret
+= scnprintf(str
+ ret
, size
- ret
, "In-Reset ");
478 ret
+= scnprintf(str
+ ret
, size
- ret
, "Change: ");
479 if (portsc
& PORT_CSC
)
480 ret
+= scnprintf(str
+ ret
, size
- ret
, "CSC ");
481 if (portsc
& PORT_WRC
)
482 ret
+= scnprintf(str
+ ret
, size
- ret
, "WRC ");
483 if (portsc
& PORT_RC
)
484 ret
+= scnprintf(str
+ ret
, size
- ret
, "PRC ");
485 if (portsc
& PORT_PLC
)
486 ret
+= scnprintf(str
+ ret
, size
- ret
, "PLC ");
487 if (portsc
& PORT_CEC
)
488 ret
+= scnprintf(str
+ ret
, size
- ret
, "CEC ");
489 ret
+= scnprintf(str
+ ret
, size
- ret
, "Wake: ");
490 if (portsc
& PORT_WKCONN_E
)
491 ret
+= scnprintf(str
+ ret
, size
- ret
, "WCE ");
492 if (portsc
& PORT_WKDISC_E
)
493 ret
+= scnprintf(str
+ ret
, size
- ret
, "WDE ");
498 static inline const char *cdnsp_ep_state_string(u8 state
)
501 case EP_STATE_DISABLED
:
503 case EP_STATE_RUNNING
:
505 case EP_STATE_HALTED
:
507 case EP_STATE_STOPPED
:
516 static inline const char *cdnsp_ep_type_string(u8 type
)
538 static inline const char *cdnsp_decode_ep_context(char *str
, size_t size
,
540 u64 deq
, u32 tx_info
)
542 u8 max_pstr
, ep_state
, interval
, ep_type
, burst
, cerr
, mult
;
548 esit
= CTX_TO_MAX_ESIT_PAYLOAD_HI(info
) << 16 |
549 CTX_TO_MAX_ESIT_PAYLOAD_LO(tx_info
);
551 ep_state
= info
& EP_STATE_MASK
;
552 max_pstr
= CTX_TO_EP_MAXPSTREAMS(info
);
553 interval
= CTX_TO_EP_INTERVAL(info
);
554 mult
= CTX_TO_EP_MULT(info
) + 1;
555 lsa
= !!(info
& EP_HAS_LSA
);
557 cerr
= (info2
& (3 << 1)) >> 1;
558 ep_type
= CTX_TO_EP_TYPE(info2
);
559 hid
= !!(info2
& (1 << 7));
560 burst
= CTX_TO_MAX_BURST(info2
);
561 maxp
= MAX_PACKET_DECODED(info2
);
563 avg
= EP_AVG_TRB_LENGTH(tx_info
);
565 ret
= scnprintf(str
, size
, "State %s mult %d max P. Streams %d %s",
566 cdnsp_ep_state_string(ep_state
), mult
,
567 max_pstr
, lsa
? "LSA " : "");
569 ret
+= scnprintf(str
+ ret
, size
- ret
,
570 "interval %d us max ESIT payload %d CErr %d ",
571 (1 << interval
) * 125, esit
, cerr
);
573 ret
+= scnprintf(str
+ ret
, size
- ret
,
574 "Type %s %sburst %d maxp %d deq %016llx ",
575 cdnsp_ep_type_string(ep_type
), hid
? "HID" : "",
578 ret
+= scnprintf(str
+ ret
, size
- ret
, "avg trb len %d", avg
);
583 #endif /*__LINUX_CDNSP_DEBUG*/