Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933288AbcDLLVY (ORCPT ); Tue, 12 Apr 2016 07:21:24 -0400 Received: from mga14.intel.com ([192.55.52.115]:62310 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932409AbcDLLVV (ORCPT ); Tue, 12 Apr 2016 07:21:21 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,473,1455004800"; d="scan'208";a="783193912" From: changbin.du@intel.com To: balbi@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Du, Changbin" Subject: [PATCH v4 2/2] usb: dwc3: add debugfs node to dump FIFO/Queue available space Date: Tue, 12 Apr 2016 19:10:19 +0800 Message-Id: <1460459419-9487-3-git-send-email-changbin.du@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1460459419-9487-1-git-send-email-changbin.du@intel.com> References: <1460459419-9487-1-git-send-email-changbin.du@intel.com> In-Reply-To: <87potwo0d2.fsf@intel.com> References: <87potwo0d2.fsf@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3258 Lines: 101 From: "Du, Changbin" For DWC3 USB controller, the Global Debug Queue/FIFO Space Available Register(GDBGFIFOSPACE) can be used to dump FIFO/Queue available space. This can be used to check some special issues, like whether data is successfully copied from memory to fifo when a trb is blocked. Signed-off-by: Du, Changbin --- v4: Do not fail silently, but print error. --- drivers/usb/dwc3/core.h | 5 +++++ drivers/usb/dwc3/debugfs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 6254b2f..899cf76 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -348,6 +348,11 @@ #define DWC3_DSTS_LOWSPEED (2 << 0) #define DWC3_DSTS_FULLSPEED1 (3 << 0) +/* Global Debug Queue/FIFO Space Available Register */ +#define DWC3_GDBGFIFOSPACE_NUM(x) (((x) << 0) & 0x1F) +#define DWC3_GDBGFIFOSPACE_TYPE(x) (((x) << 5) & 0xE0) +#define DWC3_GDBGFIFOSPACE_GET_SPACE(x) (((x) >> 16) & 0xFFFF) + /* Device Generic Command Register */ #define DWC3_DGCMD_SET_LMP 0x01 #define DWC3_DGCMD_SET_PERIODIC_PAR 0x02 diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c index 615d4dc..83e5bc1 100644 --- a/drivers/usb/dwc3/debugfs.c +++ b/drivers/usb/dwc3/debugfs.c @@ -426,6 +426,45 @@ static const struct file_operations dwc3_mode_fops = { .release = single_release, }; +static int dwc3_fifo_show(struct seq_file *s, void *unused) +{ + struct dwc3 *dwc = s->private; + unsigned long flags; + unsigned int type, index; + const char *name; + u32 reg; + + static const char * const fifo_names[] = { + "TxFIFO", "RxFIFO", "TxReqQ", "RxReqQ", "RxInfoQ", + "DescFetchQ", "EventQ", "ProtocolStatusQ"}; + spin_lock_irqsave(&dwc->lock, flags); + for (type = 0; type < 8; type++) { + name = fifo_names[type]; + for (index = 0; index < 32; index++) { + dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, + DWC3_GDBGFIFOSPACE_NUM(index) | + DWC3_GDBGFIFOSPACE_TYPE(type)); + reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); + seq_printf(s, "%s%02d = %d\n", name, index, + DWC3_GDBGFIFOSPACE_GET_SPACE(reg)); + } + } + spin_unlock_irqrestore(&dwc->lock, flags); + return 0; +} + +static int dwc3_fifo_open(struct inode *inode, struct file *file) +{ + return single_open(file, dwc3_fifo_show, inode->i_private); +} + +static const struct file_operations dwc3_fifo_fops = { + .open = dwc3_fifo_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + static int dwc3_testmode_show(struct seq_file *s, void *unused) { struct dwc3 *dwc = s->private; @@ -642,10 +681,15 @@ void dwc3_debugfs_init(struct dwc3 *dwc) dwc->regset->nregs = ARRAY_SIZE(dwc3_regs); dwc->regset->base = dwc->regs; + file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset); if (!file) dev_err(dwc->dev, "Can't create debugfs regdump\n"); + file = debugfs_create_file("fifo", S_IRUGO, root, dwc, &dwc3_fifo_fops); + if (!file) + dev_err(dwc->dev, "Can't create debugfs fifo\n"); + if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) { file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root, dwc, &dwc3_mode_fops); -- 2.5.0