18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Cadence USBSS DRD Driver.
48c2ecf20Sopenharmony_ci * Debug header file.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2018-2019 Cadence.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Author: Pawel Laszczak <pawell@cadence.com>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci#ifndef __LINUX_CDNS3_DEBUG
118c2ecf20Sopenharmony_ci#define __LINUX_CDNS3_DEBUG
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include "core.h"
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistatic inline char *cdns3_decode_usb_irq(char *str,
168c2ecf20Sopenharmony_ci					 enum usb_device_speed speed,
178c2ecf20Sopenharmony_ci					 u32 usb_ists)
188c2ecf20Sopenharmony_ci{
198c2ecf20Sopenharmony_ci	int ret;
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci	ret = sprintf(str, "IRQ %08x = ", usb_ists);
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci	if (usb_ists & (USB_ISTS_CON2I | USB_ISTS_CONI)) {
248c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "Connection %s\n",
258c2ecf20Sopenharmony_ci			       usb_speed_string(speed));
268c2ecf20Sopenharmony_ci	}
278c2ecf20Sopenharmony_ci	if (usb_ists & USB_ISTS_DIS2I || usb_ists & USB_ISTS_DISI)
288c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "Disconnection ");
298c2ecf20Sopenharmony_ci	if (usb_ists & USB_ISTS_L2ENTI)
308c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "suspended ");
318c2ecf20Sopenharmony_ci	if (usb_ists & USB_ISTS_L1ENTI)
328c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "L1 enter ");
338c2ecf20Sopenharmony_ci	if (usb_ists & USB_ISTS_L1EXTI)
348c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "L1 exit ");
358c2ecf20Sopenharmony_ci	if (usb_ists & USB_ISTS_L2ENTI)
368c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "L2 enter ");
378c2ecf20Sopenharmony_ci	if (usb_ists & USB_ISTS_L2EXTI)
388c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "L2 exit ");
398c2ecf20Sopenharmony_ci	if (usb_ists & USB_ISTS_U3EXTI)
408c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "U3 exit ");
418c2ecf20Sopenharmony_ci	if (usb_ists & USB_ISTS_UWRESI)
428c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "Warm Reset ");
438c2ecf20Sopenharmony_ci	if (usb_ists & USB_ISTS_UHRESI)
448c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "Hot Reset ");
458c2ecf20Sopenharmony_ci	if (usb_ists & USB_ISTS_U2RESI)
468c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "Reset");
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	return str;
498c2ecf20Sopenharmony_ci}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic inline  char *cdns3_decode_ep_irq(char *str,
528c2ecf20Sopenharmony_ci					 u32 ep_sts,
538c2ecf20Sopenharmony_ci					 const char *ep_name)
548c2ecf20Sopenharmony_ci{
558c2ecf20Sopenharmony_ci	int ret;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	ret = sprintf(str, "IRQ for %s: %08x ", ep_name, ep_sts);
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_SETUP)
608c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "SETUP ");
618c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_IOC)
628c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "IOC ");
638c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_ISP)
648c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "ISP ");
658c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_DESCMIS)
668c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "DESCMIS ");
678c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_STREAMR)
688c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "STREAMR ");
698c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_MD_EXIT)
708c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "MD_EXIT ");
718c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_TRBERR)
728c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "TRBERR ");
738c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_NRDY)
748c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "NRDY ");
758c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_PRIME)
768c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "PRIME ");
778c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_SIDERR)
788c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "SIDERRT ");
798c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_OUTSMM)
808c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "OUTSMM ");
818c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_ISOERR)
828c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "ISOERR ");
838c2ecf20Sopenharmony_ci	if (ep_sts & EP_STS_IOT)
848c2ecf20Sopenharmony_ci		ret += sprintf(str + ret, "IOT ");
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	return str;
878c2ecf20Sopenharmony_ci}
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistatic inline char *cdns3_decode_epx_irq(char *str,
908c2ecf20Sopenharmony_ci					 char *ep_name,
918c2ecf20Sopenharmony_ci					 u32 ep_sts)
928c2ecf20Sopenharmony_ci{
938c2ecf20Sopenharmony_ci	return cdns3_decode_ep_irq(str, ep_sts, ep_name);
948c2ecf20Sopenharmony_ci}
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cistatic inline char *cdns3_decode_ep0_irq(char *str,
978c2ecf20Sopenharmony_ci					 int dir,
988c2ecf20Sopenharmony_ci					 u32 ep_sts)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	return cdns3_decode_ep_irq(str, ep_sts,
1018c2ecf20Sopenharmony_ci				   dir ? "ep0IN" : "ep0OUT");
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/**
1058c2ecf20Sopenharmony_ci * Debug a transfer ring.
1068c2ecf20Sopenharmony_ci *
1078c2ecf20Sopenharmony_ci * Prints out all TRBs in the endpoint ring, even those after the Link TRB.
1088c2ecf20Sopenharmony_ci *.
1098c2ecf20Sopenharmony_ci */
1108c2ecf20Sopenharmony_cistatic inline char *cdns3_dbg_ring(struct cdns3_endpoint *priv_ep,
1118c2ecf20Sopenharmony_ci				   struct cdns3_trb *ring, char *str)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	dma_addr_t addr = priv_ep->trb_pool_dma;
1148c2ecf20Sopenharmony_ci	struct cdns3_trb *trb;
1158c2ecf20Sopenharmony_ci	int trb_per_sector;
1168c2ecf20Sopenharmony_ci	int ret = 0;
1178c2ecf20Sopenharmony_ci	int i;
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	trb_per_sector = GET_TRBS_PER_SEGMENT(priv_ep->type);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	trb = &priv_ep->trb_pool[priv_ep->dequeue];
1228c2ecf20Sopenharmony_ci	ret += sprintf(str + ret, "\n\t\tRing contents for %s:", priv_ep->name);
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	ret += sprintf(str + ret,
1258c2ecf20Sopenharmony_ci		       "\n\t\tRing deq index: %d, trb: %p (virt), 0x%llx (dma)\n",
1268c2ecf20Sopenharmony_ci		       priv_ep->dequeue, trb,
1278c2ecf20Sopenharmony_ci		       (unsigned long long)cdns3_trb_virt_to_dma(priv_ep, trb));
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	trb = &priv_ep->trb_pool[priv_ep->enqueue];
1308c2ecf20Sopenharmony_ci	ret += sprintf(str + ret,
1318c2ecf20Sopenharmony_ci		       "\t\tRing enq index: %d, trb: %p (virt), 0x%llx (dma)\n",
1328c2ecf20Sopenharmony_ci		       priv_ep->enqueue, trb,
1338c2ecf20Sopenharmony_ci		       (unsigned long long)cdns3_trb_virt_to_dma(priv_ep, trb));
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	ret += sprintf(str + ret,
1368c2ecf20Sopenharmony_ci		       "\t\tfree trbs: %d, CCS=%d, PCS=%d\n",
1378c2ecf20Sopenharmony_ci		       priv_ep->free_trbs, priv_ep->ccs, priv_ep->pcs);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci	if (trb_per_sector > TRBS_PER_SEGMENT)
1408c2ecf20Sopenharmony_ci		trb_per_sector = TRBS_PER_SEGMENT;
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci	if (trb_per_sector > TRBS_PER_SEGMENT) {
1438c2ecf20Sopenharmony_ci		sprintf(str + ret, "\t\tTransfer ring %d too big\n",
1448c2ecf20Sopenharmony_ci			trb_per_sector);
1458c2ecf20Sopenharmony_ci		return str;
1468c2ecf20Sopenharmony_ci	}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	for (i = 0; i < trb_per_sector; ++i) {
1498c2ecf20Sopenharmony_ci		trb = &ring[i];
1508c2ecf20Sopenharmony_ci		ret += sprintf(str + ret,
1518c2ecf20Sopenharmony_ci			"\t\t@%pad %08x %08x %08x\n", &addr,
1528c2ecf20Sopenharmony_ci			le32_to_cpu(trb->buffer),
1538c2ecf20Sopenharmony_ci			le32_to_cpu(trb->length),
1548c2ecf20Sopenharmony_ci			le32_to_cpu(trb->control));
1558c2ecf20Sopenharmony_ci		addr += sizeof(*trb);
1568c2ecf20Sopenharmony_ci	}
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	return str;
1598c2ecf20Sopenharmony_ci}
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#endif /*__LINUX_CDNS3_DEBUG*/
162