Skip to contentSkip to conversation

usb: dwc3: add debugfs node to dump FIFO/Queue available space

PATCH In review [email protected] 4 participants 30 messages Apr 6, 2016 – Apr 14, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: dwc3: add debugfs node to dump FIFO/Queue available space

From: "Du, Changbin" <[email protected]>

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.

---
 drivers/usb/dwc3/core.h    |  5 +++++
 drivers/usb/dwc3/debugfs.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
drivers/usb/dwc3/core.h +5 -0
index 6254b2f..899cf76 100644
@@ -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
drivers/usb/dwc3/debugfs.c +45 -0

57 lines not on this page · raw message

Signature · 1 line
2.5.0
maintainer
#1 lore raw
Quoted 7 lines · On Wed, Apr 06, 2016 at 04:27:23PM +0800, [email protected] wrote:

From: "Du, Changbin" <[email protected]>

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.

Quoted 5 lines
---
 drivers/usb/dwc3/core.h    |  5 +++++
 drivers/usb/dwc3/debugfs.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

Why did you not include the linux-usb@vger mailing list?

Quoted 68 lines
drivers/usb/dwc3/core.h +5 -0
index 6254b2f..899cf76 100644
@@ -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
drivers/usb/dwc3/debugfs.c +39 -0
index 9ac37fe..f9a8d9e 100644
@@ -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;

drivers/usb/dwc3/debugfs.c int dwc3_debugfs_init(struct dwc3 *dwc) · line 692

Quoted 6 lines
drivers/usb/dwc3/debugfs.c +3 -0
@@ -648,6 +687,12 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
 		goto err1;
 	}
 
+	file = debugfs_create_file("fifo", S_IRUGO, root, dwc, &dwc3_fifo_fops);
+	if (!file) {
+		ret = -ENOMEM;

Um, no, that's not the error here. You shouldn't care at all about debugfs api call results. Just keep moving on here please.

thanks,

greg k-h

#2 lore raw
Quoted 12 lines
Quoted 7 lines

This can be used to check some special issues, like whether data is successfully copied from memory to fifo when a trb is blocked.

---
 drivers/usb/dwc3/core.h    |  5 +++++
 drivers/usb/dwc3/debugfs.c | 45

+++++++++++++++++++++++++++++++++++++++++++++

Quoted 1 line
 2 files changed, 50 insertions(+)

Why did you not include the linux-usb@vger mailing list?

Just forget it :)

Quoted 15 lines

drivers/usb/dwc3/debugfs.c int dwc3_debugfs_init(struct dwc3 *dwc) · line 690

Quoted 8 lines

static int dwc3_testmode_show(struct seq_file *s, void *unused) {

drivers/usb/dwc3/debugfs.c +1 -0
 	struct dwc3		*dwc = s->private;
@@ -648,6 +687,12 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
 		goto err1;
 	}
 
+	file = debugfs_create_file("fifo", S_IRUGO, root, dwc,

&dwc3_fifo_fops);

drivers/usb/dwc3/debugfs.c int dwc3_debugfs_init(struct dwc3 *dwc) · line 692

Quoted 2 lines
drivers/usb/dwc3/debugfs.c +2 -0
+	if (!file) {
+		ret = -ENOMEM;

Um, no, that's not the error here. You shouldn't care at all about debugfs api call results. Just keep moving on here please.

Quoted 3 lines

thanks,

greg k-h

Agree with you. I will create another patch to cleanup this piece of code. And I found a memory leak issue there, dwc->regset never released. Will also fix it.

Thanks,
Du, Changbin

#3 lore raw

Hi,

(please make sure to break your lines at
80-characters. Documentation/email-clients.txt has several tips for different email clients ;-))

Quoted 12 lines · Changbin
Quoted 12 lines

drivers/usb/dwc3/debugfs.c int dwc3_debugfs_init(struct dwc3 *dwc) · line 690

Quoted 5 lines
drivers/usb/dwc3/debugfs.c +1 -0
@@ -648,6 +687,12 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
 		goto err1;
 	}
 
+	file = debugfs_create_file("fifo", S_IRUGO, root, dwc,

&dwc3_fifo_fops);

drivers/usb/dwc3/debugfs.c int dwc3_debugfs_init(struct dwc3 *dwc) · line 692

Quoted 2 lines
drivers/usb/dwc3/debugfs.c +2 -0
+	if (!file) {
+		ret = -ENOMEM;

Um, no, that's not the error here. You shouldn't care at all about debugfs api call results. Just keep moving on here please.

Quoted 6 lines
Quoted 3 lines

thanks,

greg k-h

Agree with you. I will create another patch to cleanup this piece of code.

cool, thanks

Quoted 2 lines

And I found a memory leak issue there, dwc->regset never released. Will also fix it.

good catch, thanks for fixing it.

Signature · 1 line
balbi
#4 lore raw

v2 cover Improvement, fix and new entry for dwc3 debugfs

In reply to Greg KH

From: "Du, Changbin" <[email protected]>

The first patch removed unnecessary checking for debugfs api call; The second patch fix a memory leak issue;
The third patch add one new entry to debufs.

Du, Changbin (3):
usb: dwc3: make dwc3_debugfs_init return value be void
usb: dwc3: free dwc->regset on dwc3_debugfs_exit
usb: dwc3: add debugfs node to dump FIFO/Queue available space

 drivers/usb/dwc3/core.c    | 10 +----
 drivers/usb/dwc3/core.h    |  5 +++
 drivers/usb/dwc3/debug.h   |  6 +--
 drivers/usb/dwc3/debugfs.c | 93 ++++++++++++++++++++++++++--------------------
 4 files changed, 62 insertions(+), 52 deletions(-)
Signature · 1 line
2.5.0
#5 lore raw

PATCH v2 1/3 usb: dwc3: make dwc3_debugfs_init return value be void

From: "Du, Changbin" <[email protected]>

Debugfs init failure is not so important. We can continue our job on this failure. Also no need to check debugfs_create_file call results.

---
 drivers/usb/dwc3/core.c    | 10 +---------
 drivers/usb/dwc3/debug.h   |  6 +++---
 drivers/usb/dwc3/debugfs.c | 50 ++++++++++------------------------------------
 3 files changed, 14 insertions(+), 52 deletions(-)
drivers/usb/dwc3/core.c +1 -9
index 17fd814..30f825c 100644
@@ -1062,19 +1062,11 @@ static int dwc3_probe(struct platform_device *pdev)
 	if (ret)
 		goto err5;
 
-	ret = dwc3_debugfs_init(dwc);
-	if (ret) {
-		dev_err(dev, "failed to initialize debugfs\n");
-		goto err6;
-	}
-
+	dwc3_debugfs_init(dwc);
 	pm_runtime_allow(dev);
 
 	return 0;
 
-err6:
-	dwc3_core_exit_mode(dwc);
-
 err5:
 	dwc3_event_buffers_cleanup(dwc);
 
drivers/usb/dwc3/debug.h +3 -3
index 07fbc2d..71e3180 100644
@@ -217,11 +217,11 @@ static inline const char *dwc3_gadget_event_type_string(u8 event)
 void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...);
 
 #ifdef CONFIG_DEBUG_FS
-extern int dwc3_debugfs_init(struct dwc3 *);
+extern void dwc3_debugfs_init(struct dwc3 *);
 extern void dwc3_debugfs_exit(struct dwc3 *);
 #else
-static inline int dwc3_debugfs_init(struct dwc3 *d)
-{  return 0;  }
+static inline void dwc3_debugfs_init(struct dwc3 *d)
+{  }
 static inline void dwc3_debugfs_exit(struct dwc3 *d)
 {  }
 #endif
drivers/usb/dwc3/debugfs.c +10 -40

79 lines not on this page · raw message

Signature · 1 line
2.5.0
#6 lore raw

PATCH v2 2/3 usb: dwc3: free dwc->regset on dwc3_debugfs_exit

In reply to [email protected]

From: "Du, Changbin" <[email protected]>

---
 drivers/usb/dwc3/debugfs.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/dwc3/debugfs.c +3 -0
index 071b286..2d4f397 100644
@@ -657,4 +657,7 @@ void dwc3_debugfs_exit(struct dwc3 *dwc)
 {
 	debugfs_remove_recursive(dwc->root);
 	dwc->root = NULL;
+
+	kfree(dwc->regset);
+	dwc->regset = NULL;
 }
Signature · 1 line
2.5.0
#8 lore raw

Re: [PATCH v2 2/3] usb: dwc3: free dwc->regset on dwc3_debugfs_exit

In reply to [email protected]
Quoted 2 lines · [email protected] writes:

From: "Du, Changbin" <[email protected]>

no commit log == no commit, sorry

Quoted 24 lines
---
 drivers/usb/dwc3/debugfs.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/dwc3/debugfs.c +3 -0
index 071b286..2d4f397 100644
@@ -657,4 +657,7 @@ void dwc3_debugfs_exit(struct dwc3 *dwc)
 {
 	debugfs_remove_recursive(dwc->root);
 	dwc->root = NULL;
+
+	kfree(dwc->regset);
+	dwc->regset = NULL;
 }
Signature · 6 lines
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 1 line
balbi
#9 lore raw

PATCH v2 3/3 usb: dwc3: add debugfs node to dump FIFO/Queue available space

In reply to [email protected]

From: "Du, Changbin" <[email protected]>

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.

---
 drivers/usb/dwc3/core.h    |  5 +++++
 drivers/usb/dwc3/debugfs.c | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
drivers/usb/dwc3/core.h +5 -0
index 6254b2f..899cf76 100644
@@ -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
drivers/usb/dwc3/debugfs.c +40 -0
index 2d4f397..bb608e0 100644
@@ -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;
@@ -639,6 +678,7 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
 	dwc->regset->base = dwc->regs;
 
 	debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
+	debugfs_create_file("fifo", S_IRUGO, root, dwc, &dwc3_fifo_fops);
 
 	if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE))
 		debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
Signature · 1 line
2.5.0
#10 lore raw

Re: [PATCH v2 0/3] Improvement, fix and new entry for dwc3 debugfs

In reply to [email protected]

Hi,

before I review your patches, one comment

Quoted 8 lines · [email protected] writes:

From: "Du, Changbin" <[email protected]>

The first patch removed unnecessary checking for debugfs api call; The second patch fix a memory leak issue;
The third patch add one new entry to debufs.

Du, Changbin (3):
usb: dwc3: make dwc3_debugfs_init return value be void

this is _not_ a fix

Quoted 1 line

usb: dwc3: free dwc->regset on dwc3_debugfs_exit

but this is. Why isn't this, at least, the first patch in the list ? In fact, it would be preferred that this patch be sent by itself and the following two patches should be on another branch completely without any dependencies to the memory leak fix.

Signature · 1 line
balbi
#11 lore raw

RE: [PATCH v2 0/3] Improvement, fix and new entry for dwc3 debugfs

Quoted 16 lines

before I review your patches, one comment

Quoted 8 lines · [email protected] writes:

From: "Du, Changbin" <[email protected]>

The first patch removed unnecessary checking for debugfs api call; The second patch fix a memory leak issue;
The third patch add one new entry to debufs.

Du, Changbin (3):
usb: dwc3: make dwc3_debugfs_init return value be void

this is _not_ a fix

Quoted 1 line

usb: dwc3: free dwc->regset on dwc3_debugfs_exit

Quoted 7 lines

but this is. Why isn't this, at least, the first patch in the list ? In fact, it would be preferred that this patch be sent by itself and the following two patches should be on another branch completely without any dependencies to the memory leak fix.

--
Balbi

Sure, Balbi. This will be better. I will send out patch v3 and another independent patch. Also include changelog as Greg required. Thanks for checking.

Regards,
Du, Changbin

#12 lore raw

RE: [PATCH v2 0/3] Improvement, fix and new entry for dwc3 debugfs

HI

Quoted 21 lines · Changbin
Quoted 21 lines

before I review your patches, one comment

Quoted 8 lines · [email protected] writes:

From: "Du, Changbin" <[email protected]>

The first patch removed unnecessary checking for debugfs api call; The second patch fix a memory leak issue;
The third patch add one new entry to debufs.

Du, Changbin (3):
usb: dwc3: make dwc3_debugfs_init return value be void

this is _not_ a fix

Quoted 1 line

usb: dwc3: free dwc->regset on dwc3_debugfs_exit

but this is. Why isn't this, at least, the first patch in the list ? In fact, it would be preferred that this patch be sent by itself and the following two patches should be on another branch completely without any dependencies to the memory leak fix.

Quoted 5 lines
Quoted 2 lines

--
Balbi

Sure, Balbi. This will be better. I will send out patch v3 and another independent patch. Also include changelog as Greg required. Thanks for checking.

thanks, that way we can get the fix during the -rc cycle and the other two patches on next merge window ;-)

Signature · 1 line
balbi
#13 lore raw

v3 cover Add a new debugfs entry to dump FIFO/Queue available space

In reply to Felipe Balbi

From: "Du, Changbin" <[email protected]>

FIFO/Queue available space info can be used to debug dwc3 issues. First we remove unnecessary checking for debugfs api call, then add the new entry.

changes from v2:
1. Remove commit "usb: dwc3: free dwc->regset on dwc3_debugfs_exit"

Du, Changbin (2):
usb: dwc3: make dwc3_debugfs_init return value be void
usb: dwc3: add debugfs node to dump FIFO/Queue available space

 drivers/usb/dwc3/core.c    | 10 +-----
 drivers/usb/dwc3/core.h    |  5 +++
 drivers/usb/dwc3/debug.h   |  6 ++--
 drivers/usb/dwc3/debugfs.c | 90 +++++++++++++++++++++++++---------------------
 4 files changed, 59 insertions(+), 52 deletions(-)
Signature · 1 line
2.5.0
#14 lore raw

PATCH v3 1/2 usb: dwc3: make dwc3_debugfs_init return value be void

From: "Du, Changbin" <[email protected]>

Debugfs init failure is not so important. We can continue our job on this failure. Also no need to check debugfs_create_file call results.

---
changes from v2:
no changes

---
 drivers/usb/dwc3/core.c    | 10 +---------
 drivers/usb/dwc3/debug.h   |  6 +++---
 drivers/usb/dwc3/debugfs.c | 50 ++++++++++------------------------------------
 3 files changed, 14 insertions(+), 52 deletions(-)
drivers/usb/dwc3/core.c +1 -9
index 17fd814..30f825c 100644
@@ -1062,19 +1062,11 @@ static int dwc3_probe(struct platform_device *pdev)
 	if (ret)
 		goto err5;
 
-	ret = dwc3_debugfs_init(dwc);
-	if (ret) {
-		dev_err(dev, "failed to initialize debugfs\n");
-		goto err6;
-	}
-
+	dwc3_debugfs_init(dwc);
 	pm_runtime_allow(dev);
 
 	return 0;
 
-err6:
-	dwc3_core_exit_mode(dwc);
-
 err5:
 	dwc3_event_buffers_cleanup(dwc);
 
drivers/usb/dwc3/debug.h +3 -3
index 07fbc2d..71e3180 100644
@@ -217,11 +217,11 @@ static inline const char *dwc3_gadget_event_type_string(u8 event)
 void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...);
 
 #ifdef CONFIG_DEBUG_FS
-extern int dwc3_debugfs_init(struct dwc3 *);
+extern void dwc3_debugfs_init(struct dwc3 *);
 extern void dwc3_debugfs_exit(struct dwc3 *);
 #else
-static inline int dwc3_debugfs_init(struct dwc3 *d)
-{  return 0;  }
+static inline void dwc3_debugfs_init(struct dwc3 *d)
+{  }
 static inline void dwc3_debugfs_exit(struct dwc3 *d)
 {  }
 #endif
drivers/usb/dwc3/debugfs.c +10 -40

79 lines not on this page · raw message

Signature · 1 line
2.5.0
#15 lore raw

Re: [PATCH v3 1/2] usb: dwc3: make dwc3_debugfs_init return value be void

Hi,

Quoted 31 lines · [email protected] writes:
drivers/usb/dwc3/debug.h +3 -3
index 07fbc2d..71e3180 100644
@@ -217,11 +217,11 @@ static inline const char *dwc3_gadget_event_type_string(u8 event)
 void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...);
 
 #ifdef CONFIG_DEBUG_FS
-extern int dwc3_debugfs_init(struct dwc3 *);
+extern void dwc3_debugfs_init(struct dwc3 *);
 extern void dwc3_debugfs_exit(struct dwc3 *);
 #else
-static inline int dwc3_debugfs_init(struct dwc3 *d)
-{  return 0;  }
+static inline void dwc3_debugfs_init(struct dwc3 *d)
+{  }
 static inline void dwc3_debugfs_exit(struct dwc3 *d)
 {  }
 #endif
drivers/usb/dwc3/debugfs.c +1 -1
index 9ac37fe..071b286 100644
@@ -618,69 +618,39 @@ static const struct file_operations dwc3_link_state_fops = {
 	.release		= single_release,
 };
 
-int dwc3_debugfs_init(struct dwc3 *dwc)
+void dwc3_debugfs_init(struct dwc3 *dwc)
 {
 	struct dentry		*root;

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_link_state_fops = { · line 627

Quoted 10 lines
drivers/usb/dwc3/debugfs.c +2 -6
-	struct dentry		*file;
-	int			ret;
 
 	root = debugfs_create_dir(dev_name(dwc->dev), NULL);
-	if (!root) {
-		ret = -ENOMEM;
-		goto err0;
-	}
+	if (IS_ERR_OR_NULL(root))
+		return;

We can definitely keep on going, but I'd still like to know that we enabled CONFIG_DEBUG_FS but failed to create a file or a directory. Seems like this should read as follows:

	if (IS_ERR_OR_NULL(root)) {
        	if (!root)
                	dev_err(dwc->dev, "Can't create debugfs root\n");
        	return;
	}

ditto to all bellow.

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_link_state_fops = { · line 633

Quoted 7 lines
drivers/usb/dwc3/debugfs.c +1 -2
 	dwc->root = root;
 
 	dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL);
 	if (!dwc->regset) {
-		ret = -ENOMEM;
-		goto err1;
+		debugfs_remove_recursive(root);

you're now duplicating debugfs_remove_recursive(root) in all braches and that's error prone. It's probably better to keep our gotos, but change them so they read as follows:

	if (!dwc->regset)
        	goto err1;

	[...]

        return; /* this is our successful exit point */

err1:

	debugfs_remove_recursive(root);
        kfree(dwc->regset);
Signature · 1 line
balbi
#16 lore raw

RE: [PATCH v3 1/2] usb: dwc3: make dwc3_debugfs_init return value be void

Quoted 12 lines

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_link_state_fops = { · line 627

Quoted 7 lines
drivers/usb/dwc3/debugfs.c +2 -4
 	root = debugfs_create_dir(dev_name(dwc->dev), NULL);
-	if (!root) {
-		ret = -ENOMEM;
-		goto err0;
-	}
+	if (IS_ERR_OR_NULL(root))
+		return;

We can definitely keep on going, but I'd still like to know that we enabled CONFIG_DEBUG_FS but failed to create a file or a directory. Seems like this should read as follows:

Quoted 8 lines
	if (IS_ERR_OR_NULL(root)) {
        	if (!root)
                	dev_err(dwc->dev, "Can't create debugfs root\n");
        	return;
	}

ditto to all bellow.

Balbi, so you mean we should not let the failure go silent, right?

Quoted 19 lines

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_link_state_fops = { · line 633

Quoted 7 lines
drivers/usb/dwc3/debugfs.c +1 -2
 	dwc->root = root;
 
 	dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL);
 	if (!dwc->regset) {
-		ret = -ENOMEM;
-		goto err1;
+		debugfs_remove_recursive(root);

you're now duplicating debugfs_remove_recursive(root) in all braches and that's error prone. It's probably better to keep our gotos, but change them so they read as follows:

	if (!dwc->regset)
        	goto err1;

	[...]

        return; /* this is our successful exit point */
Quoted 7 lines

err1:

	debugfs_remove_recursive(root);
        kfree(dwc->regset);

--
Balbi

No, no need anymore. Because no branch share this code now. Then remove the goto would make code a little clear.

Thanks,
Du, Changbin

#17 lore raw

RE: [PATCH v3 1/2] usb: dwc3: make dwc3_debugfs_init return value be void

Hi,

Quoted 18 lines · Changbin
Quoted 18 lines

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_link_state_fops = { · line 627

Quoted 7 lines
drivers/usb/dwc3/debugfs.c +2 -4
 	root = debugfs_create_dir(dev_name(dwc->dev), NULL);
-	if (!root) {
-		ret = -ENOMEM;
-		goto err0;
-	}
+	if (IS_ERR_OR_NULL(root))
+		return;

We can definitely keep on going, but I'd still like to know that we enabled CONFIG_DEBUG_FS but failed to create a file or a directory. Seems like this should read as follows:

	if (IS_ERR_OR_NULL(root)) {
        	if (!root)
                	dev_err(dwc->dev, "Can't create debugfs root\n");
        	return;
	}
Quoted 3 lines
Quoted 2 lines

ditto to all bellow.

Balbi, so you mean we should not let the failure go silent, right?

yeah, but only iff CONFIG_DEBUG_FS is enabled. From what I can tell, in case CONFIG_DEBUG_FS is enabled and it fails, it'll return a NULL pointer instead of ERR_PTR() ;-)

Quoted 24 lines
Quoted 24 lines

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_link_state_fops = { · line 633

Quoted 7 lines
drivers/usb/dwc3/debugfs.c +1 -2
 	dwc->root = root;
 
 	dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL);
 	if (!dwc->regset) {
-		ret = -ENOMEM;
-		goto err1;
+		debugfs_remove_recursive(root);

you're now duplicating debugfs_remove_recursive(root) in all braches and that's error prone. It's probably better to keep our gotos, but change them so they read as follows:

	if (!dwc->regset)
        	goto err1;

	[...]

        return; /* this is our successful exit point */

err1:

	debugfs_remove_recursive(root);
        kfree(dwc->regset);
Quoted 5 lines
Quoted 2 lines

--
Balbi

No, no need anymore. Because no branch share this code now. Then remove the goto would make code a little clear.

fair enough.

Signature · 1 line
balbi
#18 lore raw

v4 cover Add a new debugfs entry to dump FIFO/Queue available space

From: "Du, Changbin" <[email protected]>

FIFO/Queue available space info can be used to debug dwc3 issues. First we remove unnecessary checking for debugfs api call, then add the new entry.

Du, Changbin (2):
usb: dwc3: make dwc3_debugfs_init return value be void
usb: dwc3: add debugfs node to dump FIFO/Queue available space

 drivers/usb/dwc3/core.c    | 10 +----
 drivers/usb/dwc3/core.h    |  5 +++
 drivers/usb/dwc3/debug.h   |  6 +--
 drivers/usb/dwc3/debugfs.c | 98 +++++++++++++++++++++++++++++-----------------
 4 files changed, 72 insertions(+), 47 deletions(-)
Signature · 1 line
2.5.0
#19 lore raw

PATCH v4 1/2 usb: dwc3: make dwc3_debugfs_init return value be void

From: "Du, Changbin" <[email protected]>

Debugfs init failure is not so important. We can continue our job on this failure. Also no break need for debugfs_create_file call failure.

---
v4:
Do not fail silently, but print error.

---
 drivers/usb/dwc3/core.c    | 10 +--------
 drivers/usb/dwc3/debug.h   |  6 ++---
 drivers/usb/dwc3/debugfs.c | 56 +++++++++++++++++-----------------------------
 3 files changed, 24 insertions(+), 48 deletions(-)
drivers/usb/dwc3/core.c +1 -9
index 17fd814..30f825c 100644
@@ -1062,19 +1062,11 @@ static int dwc3_probe(struct platform_device *pdev)
 	if (ret)
 		goto err5;
 
-	ret = dwc3_debugfs_init(dwc);
-	if (ret) {
-		dev_err(dev, "failed to initialize debugfs\n");
-		goto err6;
-	}
-
+	dwc3_debugfs_init(dwc);
 	pm_runtime_allow(dev);
 
 	return 0;
 
-err6:
-	dwc3_core_exit_mode(dwc);
-
 err5:
 	dwc3_event_buffers_cleanup(dwc);
 
drivers/usb/dwc3/debug.h +3 -3
index 07fbc2d..71e3180 100644
@@ -217,11 +217,11 @@ static inline const char *dwc3_gadget_event_type_string(u8 event)
 void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...);
 
 #ifdef CONFIG_DEBUG_FS
-extern int dwc3_debugfs_init(struct dwc3 *);
+extern void dwc3_debugfs_init(struct dwc3 *);
 extern void dwc3_debugfs_exit(struct dwc3 *);
 #else
-static inline int dwc3_debugfs_init(struct dwc3 *d)
-{  return 0;  }
+static inline void dwc3_debugfs_init(struct dwc3 *d)
+{  }
 static inline void dwc3_debugfs_exit(struct dwc3 *d)
 {  }
 #endif
drivers/usb/dwc3/debugfs.c +20 -36

88 lines not on this page · raw message

Signature · 1 line
2.5.0
#20 lore raw

PATCH v4 2/2 usb: dwc3: add debugfs node to dump FIFO/Queue available space

In reply to [email protected]

From: "Du, Changbin" <[email protected]>

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.

---
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(+)
drivers/usb/dwc3/core.h +5 -0
index 6254b2f..899cf76 100644
@@ -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
drivers/usb/dwc3/debugfs.c +44 -0

60 lines not on this page · raw message

Signature · 1 line
2.5.0
#21 lore raw

Hello.

Quoted 4 lines · On 4/12/2016 2:10 PM, [email protected] wrote:

From: "Du, Changbin" <[email protected]>

For DWC3 USB controller, the Global Debug Queue/FIFO Space Available Register(GDBGFIFOSPACE) can be used to dump FIFO/Queue available space.

Space needed before (.

Quoted 7 lines

This can be used to check some special issues, like whether data is successfully copied from memory to fifo when a trb is blocked.

---
v4:
Do not fail silently, but print error.

[...]

Quoted 4 lines
drivers/usb/dwc3/debugfs.c +0 -0
index 615d4dc..83e5bc1 100644

[...]

drivers/usb/dwc3/debugfs.c void dwc3_debugfs_init(struct dwc3 *dwc) · line 684

Quoted 5 lines
drivers/usb/dwc3/debugfs.c +1 -0
@@ -642,10 +681,15 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
  	dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
  	dwc->regset->base = dwc->regs;
 
+

Why?

drivers/usb/dwc3/debugfs.c void dwc3_debugfs_init(struct dwc3 *dwc) · line 695

Quoted 11 lines
drivers/usb/dwc3/debugfs.c +4 -0
  	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);

MBR, Sergei

#22 lore raw

Hello, Sergei,

Quoted 7 lines
Quoted 4 lines

From: "Du, Changbin" <[email protected]>

For DWC3 USB controller, the Global Debug Queue/FIFO Space Available Register(GDBGFIFOSPACE) can be used to dump FIFO/Queue available

space.

Space needed before (.

Okay.

Quoted 14 lines
Quoted 8 lines

This can be used to check some special issues, like whether data is successfully copied from memory to fifo when a trb is blocked.

---
v4:
Do not fail silently, but print error.

[...]

Quoted 4 lines
drivers/usb/dwc3/debugfs.c +0 -0
index 615d4dc..83e5bc1 100644

[...]

Quoted 7 lines

drivers/usb/dwc3/debugfs.c void dwc3_debugfs_init(struct dwc3 *dwc) · line 684

Quoted 5 lines
drivers/usb/dwc3/debugfs.c +1 -0
@@ -642,10 +681,15 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
  	dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
  	dwc->regset->base = dwc->regs;
 
+

Why?

Thanks for point out, I will remove this additional line.

Quoted 17 lines

drivers/usb/dwc3/debugfs.c void dwc3_debugfs_init(struct dwc3 *dwc)

Quoted 7 lines
drivers/usb/dwc3/debugfs.c +1 -0
  	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);

drivers/usb/dwc3/debugfs.c void dwc3_debugfs_init(struct dwc3 *dwc)

Quoted 5 lines
drivers/usb/dwc3/debugfs.c +3 -0
+	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,

Quoted 1 line

dwc, &dwc3_mode_fops);

MBR, Sergei

#23 lore raw
In reply to [email protected]

Hi,

Quoted 22 lines · [email protected] writes:

From: "Du, Changbin" <[email protected]>

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.

---
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(+)
drivers/usb/dwc3/core.h +0 -0
index 6254b2f..899cf76 100644

drivers/usb/dwc3/core.h line 354

Quoted 7 lines
drivers/usb/dwc3/core.h +4 -0
@@ -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)

we always use lower case hex numbers. Also, databook refers to top 16 bits as "Space Avaiable" so I'd prefer that you called this macro:

DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(x)

as that will aid with grepping

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_mode_fops = { · line 429

Quoted 9 lines
drivers/usb/dwc3/debugfs.c +1 -0
index 615d4dc..83e5bc1 100644
@@ -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)

you call this file 'fifo' however you print more than just the fifos. You printk the request queues, info queue, descriptor fetch queue, event queue and protocol status queue.

It seems, to me, you're trying to do way too much in a single file.

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_mode_fops = { · line 441

Quoted 12 lines
drivers/usb/dwc3/debugfs.c +12 -0
+{
+	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++) {

type < ARRAY_SIZE(fifo_names) ??

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_mode_fops = { · line 443

Quoted 2 lines
drivers/usb/dwc3/debugfs.c +2 -0
+		name = fifo_names[type];
+		for (index = 0; index < 32; index++) {

not *all* dwc3 implementations enable all 32 endpoints, that's why we have dwc->num_endpoints

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_mode_fops = { · line 447

Quoted 4 lines
drivers/usb/dwc3/debugfs.c +4 -0
+			dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE,
+				DWC3_GDBGFIFOSPACE_NUM(index) |
+				DWC3_GDBGFIFOSPACE_TYPE(type));
+			reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE);

this writel() followed by a readl() could be a nice little helper function in core.c. Remember that we need the FIFO Space and link state to make sure we're allowed to start a transfer ;-)

I'd suggesting adding the following to core.c:

int dwc3_core_fifo_space(struct dwc3_ep *dep, unsigned int type)

{
	u32 reg;

        dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE,
        	DWC3_GDBGFIFOSPACE_NUM(dep->number) |
                DWC3_GDBGFIFOSPACE_TYPE(type));

	reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE);

	return DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(reg);
}

then, add the prototype to core.h. (both of these in a separate patch).

Then $subject just uses that helper to print out the data you want to print. I still think we might be better off with one file per type (iow TX fifo file, RX fifo file, TX request queue file, and so on).

In fact, we could actually have a per-endpoint directory where all of these details are printed out in a much more structured form. If you want, I can work on that, no problem, but you're also welcome to implement it yourself and I'd be around to help as needed.

In summary, we should have our debugfs looking like so:

./ep0
./ep0/descriptor_fetch_queue
./ep0/event_queue
./ep0/info_queue
./ep0/protocol_status_queue
./ep0/request_queue
./ep0/rx_fifo
./ep0/rx_request_queue
./ep0/tx_fifo
./ep0/tx_request_queue
./ep1
./ep10
./ep10/descriptor_fetch_queue
./ep10/event_queue
./ep10/info_queue
./ep10/protocol_status_queue
./ep10/request_queue
./ep10/rx_fifo
./ep10/rx_request_queue
./ep10/tx_fifo
./ep10/tx_request_queue
./ep11
./ep11/descriptor_fetch_queue
./ep11/event_queue
./ep11/info_queue
./ep11/protocol_status_queue
./ep11/request_queue
./ep11/rx_fifo
./ep11/rx_request_queue
./ep11/tx_fifo
./ep11/tx_request_queue
./ep12
./ep12/descriptor_fetch_queue
./ep12/event_queue
./ep12/info_queue
./ep12/protocol_status_queue
./ep12/request_queue
./ep12/rx_fifo
./ep12/rx_request_queue
./ep12/tx_fifo
./ep12/tx_request_queue
./ep13
./ep13/descriptor_fetch_queue
./ep13/event_queue
./ep13/info_queue
./ep13/protocol_status_queue
./ep13/request_queue
./ep13/rx_fifo
./ep13/rx_request_queue
./ep13/tx_fifo
./ep13/tx_request_queue
./ep14
./ep14/descriptor_fetch_queue
./ep14/event_queue
./ep14/info_queue
./ep14/protocol_status_queue
./ep14/request_queue
./ep14/rx_fifo
./ep14/rx_request_queue
./ep14/tx_fifo
./ep14/tx_request_queue
./ep15
./ep15/descriptor_fetch_queue
./ep15/event_queue
./ep15/info_queue
./ep15/protocol_status_queue
./ep15/request_queue
./ep15/rx_fifo
./ep15/rx_request_queue
./ep15/tx_fifo
./ep15/tx_request_queue
./ep16
./ep16/descriptor_fetch_queue
./ep16/event_queue
./ep16/info_queue
./ep16/protocol_status_queue
./ep16/request_queue
./ep16/rx_fifo
./ep16/rx_request_queue
./ep16/tx_fifo
./ep16/tx_request_queue
./ep17
./ep17/descriptor_fetch_queue
./ep17/event_queue
./ep17/info_queue
./ep17/protocol_status_queue
./ep17/request_queue
./ep17/rx_fifo
./ep17/rx_request_queue
./ep17/tx_fifo
./ep17/tx_request_queue
./ep18
./ep18/descriptor_fetch_queue
./ep18/event_queue
./ep18/info_queue
./ep18/protocol_status_queue
./ep18/request_queue
./ep18/rx_fifo
./ep18/rx_request_queue
./ep18/tx_fifo
./ep18/tx_request_queue
./ep19
./ep19/descriptor_fetch_queue
./ep19/event_queue
./ep19/info_queue
./ep19/protocol_status_queue
./ep19/request_queue
./ep19/rx_fifo
./ep19/rx_request_queue
./ep19/tx_fifo
./ep19/tx_request_queue
./ep1/descriptor_fetch_queue
./ep1/event_queue
./ep1/info_queue
./ep1/protocol_status_queue
./ep1/request_queue
./ep1/rx_fifo
./ep1/rx_request_queue
./ep1/tx_fifo
./ep1/tx_request_queue
./ep2
./ep20
./ep20/descriptor_fetch_queue
./ep20/event_queue
./ep20/info_queue
./ep20/protocol_status_queue
./ep20/request_queue
./ep20/rx_fifo
./ep20/rx_request_queue
./ep20/tx_fifo
./ep20/tx_request_queue
./ep21
./ep21/descriptor_fetch_queue
./ep21/event_queue
./ep21/info_queue
./ep21/protocol_status_queue
./ep21/request_queue
./ep21/rx_fifo
./ep21/rx_request_queue
./ep21/tx_fifo
./ep21/tx_request_queue
./ep22
./ep22/descriptor_fetch_queue
./ep22/event_queue
./ep22/info_queue
./ep22/protocol_status_queue
./ep22/request_queue
./ep22/rx_fifo
./ep22/rx_request_queue
./ep22/tx_fifo
./ep22/tx_request_queue
./ep23
./ep23/descriptor_fetch_queue
./ep23/event_queue
./ep23/info_queue
./ep23/protocol_status_queue
./ep23/request_queue
./ep23/rx_fifo
./ep23/rx_request_queue
./ep23/tx_fifo
./ep23/tx_request_queue
./ep24
./ep24/descriptor_fetch_queue
./ep24/event_queue
./ep24/info_queue
./ep24/protocol_status_queue
./ep24/request_queue
./ep24/rx_fifo
./ep24/rx_request_queue
./ep24/tx_fifo
./ep24/tx_request_queue
./ep25
./ep25/descriptor_fetch_queue
./ep25/event_queue
./ep25/info_queue
./ep25/protocol_status_queue
./ep25/request_queue
./ep25/rx_fifo
./ep25/rx_request_queue
./ep25/tx_fifo
./ep25/tx_request_queue
./ep26
./ep26/descriptor_fetch_queue
./ep26/event_queue
./ep26/info_queue
./ep26/protocol_status_queue
./ep26/request_queue
./ep26/rx_fifo
./ep26/rx_request_queue
./ep26/tx_fifo
./ep26/tx_request_queue
./ep27
./ep27/descriptor_fetch_queue
./ep27/event_queue
./ep27/info_queue
./ep27/protocol_status_queue
./ep27/request_queue
./ep27/rx_fifo
./ep27/rx_request_queue
./ep27/tx_fifo
./ep27/tx_request_queue
./ep28
./ep28/descriptor_fetch_queue
./ep28/event_queue
./ep28/info_queue
./ep28/protocol_status_queue
./ep28/request_queue
./ep28/rx_fifo
./ep28/rx_request_queue
./ep28/tx_fifo
./ep28/tx_request_queue
./ep29
./ep29/descriptor_fetch_queue
./ep29/event_queue
./ep29/info_queue
./ep29/protocol_status_queue
./ep29/request_queue
./ep29/rx_fifo
./ep29/rx_request_queue
./ep29/tx_fifo
./ep29/tx_request_queue
./ep2/descriptor_fetch_queue
./ep2/event_queue
./ep2/info_queue
./ep2/protocol_status_queue
./ep2/request_queue
./ep2/rx_fifo
./ep2/rx_request_queue
./ep2/tx_fifo
./ep2/tx_request_queue
./ep3
./ep30
./ep30/descriptor_fetch_queue
./ep30/event_queue
./ep30/info_queue
./ep30/protocol_status_queue
./ep30/request_queue
./ep30/rx_fifo
./ep30/rx_request_queue
./ep30/tx_fifo
./ep30/tx_request_queue
./ep31
./ep31/descriptor_fetch_queue
./ep31/event_queue
./ep31/info_queue
./ep31/protocol_status_queue
./ep31/request_queue
./ep31/rx_fifo
./ep31/rx_request_queue
./ep31/tx_fifo
./ep31/tx_request_queue
./ep3/descriptor_fetch_queue
./ep3/event_queue
./ep3/info_queue
./ep3/protocol_status_queue
./ep3/request_queue
./ep3/rx_fifo
./ep3/rx_request_queue
./ep3/tx_fifo
./ep3/tx_request_queue
./ep4
./ep4/descriptor_fetch_queue
./ep4/event_queue
./ep4/info_queue
./ep4/protocol_status_queue
./ep4/request_queue
./ep4/rx_fifo
./ep4/rx_request_queue
./ep4/tx_fifo
./ep4/tx_request_queue
./ep5
./ep5/descriptor_fetch_queue
./ep5/event_queue
./ep5/info_queue
./ep5/protocol_status_queue
./ep5/request_queue
./ep5/rx_fifo
./ep5/rx_request_queue
./ep5/tx_fifo
./ep5/tx_request_queue
./ep6
./ep6/descriptor_fetch_queue
./ep6/event_queue
./ep6/info_queue
./ep6/protocol_status_queue
./ep6/request_queue
./ep6/rx_fifo
./ep6/rx_request_queue
./ep6/tx_fifo
./ep6/tx_request_queue
./ep7
./ep7/descriptor_fetch_queue
./ep7/event_queue
./ep7/info_queue
./ep7/protocol_status_queue
./ep7/request_queue
./ep7/rx_fifo
./ep7/rx_request_queue
./ep7/tx_fifo
./ep7/tx_request_queue
./ep8
./ep8/descriptor_fetch_queue
./ep8/event_queue
./ep8/info_queue
./ep8/protocol_status_queue
./ep8/request_queue
./ep8/rx_fifo
./ep8/rx_request_queue
./ep8/tx_fifo
./ep8/tx_request_queue
./ep9
./ep9/descriptor_fetch_queue
./ep9/event_queue
./ep9/info_queue
./ep9/protocol_status_queue
./ep9/request_queue
./ep9/rx_fifo
./ep9/rx_request_queue
./ep9/tx_fifo
./ep9/tx_request_queue
./link_state
./mode
./regdump
./testmode

Signature · 1 line
balbi
#24 lore raw

Hi, Balbi.
Feel free to change it, I may not have enough time on this currently. "per-endpoint directory" is great idea, then we do not need find out wanted info from one big file, but just go to specific dir.

Btw, I'd mention that not all out ep has a rx fifo. So in my original patch, not all FIFO/Queue info are valid. We need pick out the real info we need. And I didn't find any method to read the FIFO map.

At last, comparing with the FIFO/Queue info, I think software transfer Requests list, TRBs info, EVENTs history are much more useful for debugging the driver. If you can also add these info to each EP folder, that is awesome! :)

Best Regards,
Du, Changbin

Quoted 455 lines

-----Original Message-----
From: Felipe Balbi [mailto:[email protected]]
Sent: Thursday, April 14, 2016 4:03 PM
To: Du, Changbin <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; Du, Changbin <[email protected]>
Subject: Re: [PATCH v4 2/2] usb: dwc3: add debugfs node to dump FIFO/Queue available space

Hi,

Quoted 4 lines · [email protected] writes:

From: "Du, Changbin" <[email protected]>

For DWC3 USB controller, the Global Debug Queue/FIFO Space Available Register(GDBGFIFOSPACE) can be used to dump FIFO/Queue available

space.

Quoted 11 lines

This can be used to check some special issues, like whether data is successfully copied from memory to fifo when a trb is blocked.

---
v4:
Do not fail silently, but print error.

---
 drivers/usb/dwc3/core.h    |  5 +++++
 drivers/usb/dwc3/debugfs.c | 44

++++++++++++++++++++++++++++++++++++++++++++

Quoted 7 lines
 2 files changed, 49 insertions(+)
drivers/usb/dwc3/core.h +0 -0
index 6254b2f..899cf76 100644

drivers/usb/dwc3/core.h line 354

Quoted 7 lines
drivers/usb/dwc3/core.h +4 -0
@@ -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)

we always use lower case hex numbers. Also, databook refers to top 16 bits as "Space Avaiable" so I'd prefer that you called this macro:

DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(x)

as that will aid with grepping

drivers/usb/dwc3/debugfs.c static const struct file_operations

Quoted 5 lines
drivers/usb/dwc3/debugfs.c +0 -0
index 615d4dc..83e5bc1 100644
@@ -426,6 +426,45 @@ static const struct file_operations

dwc3_mode_fops = {

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_mode_fops = { · line 429

Quoted 4 lines
drivers/usb/dwc3/debugfs.c +1 -0
 	.release		= single_release,
 };
 
+static int dwc3_fifo_show(struct seq_file *s, void *unused)

you call this file 'fifo' however you print more than just the fifos. You printk the request queues, info queue, descriptor fetch queue, event queue and protocol status queue.

It seems, to me, you're trying to do way too much in a single file.

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_mode_fops = { · line 441

Quoted 12 lines
drivers/usb/dwc3/debugfs.c +12 -0
+{
+	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++) {

type < ARRAY_SIZE(fifo_names) ??

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_mode_fops = { · line 443

Quoted 2 lines
drivers/usb/dwc3/debugfs.c +2 -0
+		name = fifo_names[type];
+		for (index = 0; index < 32; index++) {

not *all* dwc3 implementations enable all 32 endpoints, that's why we have dwc->num_endpoints

drivers/usb/dwc3/debugfs.c static const struct file_operations dwc3_mode_fops = {

Quoted 4 lines
drivers/usb/dwc3/debugfs.c +4 -0
+			dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE,
+				DWC3_GDBGFIFOSPACE_NUM(index) |
+				DWC3_GDBGFIFOSPACE_TYPE(type));
+			reg = dwc3_readl(dwc->regs,

DWC3_GDBGFIFOSPACE);

this writel() followed by a readl() could be a nice little helper function in core.c. Remember that we need the FIFO Space and link state to make sure we're allowed to start a transfer ;-)

I'd suggesting adding the following to core.c:

int dwc3_core_fifo_space(struct dwc3_ep *dep, unsigned int type)

{
	u32 reg;

        dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE,
        	DWC3_GDBGFIFOSPACE_NUM(dep->number) |
                DWC3_GDBGFIFOSPACE_TYPE(type));

	reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE);

	return DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(reg);
}

then, add the prototype to core.h. (both of these in a separate patch).

Then $subject just uses that helper to print out the data you want to print. I still think we might be better off with one file per type (iow TX fifo file, RX fifo file, TX request queue file, and so on).

In fact, we could actually have a per-endpoint directory where all of these details are printed out in a much more structured form. If you want, I can work on that, no problem, but you're also welcome to implement it yourself and I'd be around to help as needed.

In summary, we should have our debugfs looking like so:

./ep0
./ep0/descriptor_fetch_queue
./ep0/event_queue
./ep0/info_queue
./ep0/protocol_status_queue
./ep0/request_queue
./ep0/rx_fifo
./ep0/rx_request_queue
./ep0/tx_fifo
./ep0/tx_request_queue
./ep1
./ep10
./ep10/descriptor_fetch_queue
./ep10/event_queue
./ep10/info_queue
./ep10/protocol_status_queue
./ep10/request_queue
./ep10/rx_fifo
./ep10/rx_request_queue
./ep10/tx_fifo
./ep10/tx_request_queue
./ep11
./ep11/descriptor_fetch_queue
./ep11/event_queue
./ep11/info_queue
./ep11/protocol_status_queue
./ep11/request_queue
./ep11/rx_fifo
./ep11/rx_request_queue
./ep11/tx_fifo
./ep11/tx_request_queue
./ep12
./ep12/descriptor_fetch_queue
./ep12/event_queue
./ep12/info_queue
./ep12/protocol_status_queue
./ep12/request_queue
./ep12/rx_fifo
./ep12/rx_request_queue
./ep12/tx_fifo
./ep12/tx_request_queue
./ep13
./ep13/descriptor_fetch_queue
./ep13/event_queue
./ep13/info_queue
./ep13/protocol_status_queue
./ep13/request_queue
./ep13/rx_fifo
./ep13/rx_request_queue
./ep13/tx_fifo
./ep13/tx_request_queue
./ep14
./ep14/descriptor_fetch_queue
./ep14/event_queue
./ep14/info_queue
./ep14/protocol_status_queue
./ep14/request_queue
./ep14/rx_fifo
./ep14/rx_request_queue
./ep14/tx_fifo
./ep14/tx_request_queue
./ep15
./ep15/descriptor_fetch_queue
./ep15/event_queue
./ep15/info_queue
./ep15/protocol_status_queue
./ep15/request_queue
./ep15/rx_fifo
./ep15/rx_request_queue
./ep15/tx_fifo
./ep15/tx_request_queue
./ep16
./ep16/descriptor_fetch_queue
./ep16/event_queue
./ep16/info_queue
./ep16/protocol_status_queue
./ep16/request_queue
./ep16/rx_fifo
./ep16/rx_request_queue
./ep16/tx_fifo
./ep16/tx_request_queue
./ep17
./ep17/descriptor_fetch_queue
./ep17/event_queue
./ep17/info_queue
./ep17/protocol_status_queue
./ep17/request_queue
./ep17/rx_fifo
./ep17/rx_request_queue
./ep17/tx_fifo
./ep17/tx_request_queue
./ep18
./ep18/descriptor_fetch_queue
./ep18/event_queue
./ep18/info_queue
./ep18/protocol_status_queue
./ep18/request_queue
./ep18/rx_fifo
./ep18/rx_request_queue
./ep18/tx_fifo
./ep18/tx_request_queue
./ep19
./ep19/descriptor_fetch_queue
./ep19/event_queue
./ep19/info_queue
./ep19/protocol_status_queue
./ep19/request_queue
./ep19/rx_fifo
./ep19/rx_request_queue
./ep19/tx_fifo
./ep19/tx_request_queue
./ep1/descriptor_fetch_queue
./ep1/event_queue
./ep1/info_queue
./ep1/protocol_status_queue
./ep1/request_queue
./ep1/rx_fifo
./ep1/rx_request_queue
./ep1/tx_fifo
./ep1/tx_request_queue
./ep2
./ep20
./ep20/descriptor_fetch_queue
./ep20/event_queue
./ep20/info_queue
./ep20/protocol_status_queue
./ep20/request_queue
./ep20/rx_fifo
./ep20/rx_request_queue
./ep20/tx_fifo
./ep20/tx_request_queue
./ep21
./ep21/descriptor_fetch_queue
./ep21/event_queue
./ep21/info_queue
./ep21/protocol_status_queue
./ep21/request_queue
./ep21/rx_fifo
./ep21/rx_request_queue
./ep21/tx_fifo
./ep21/tx_request_queue
./ep22
./ep22/descriptor_fetch_queue
./ep22/event_queue
./ep22/info_queue
./ep22/protocol_status_queue
./ep22/request_queue
./ep22/rx_fifo
./ep22/rx_request_queue
./ep22/tx_fifo
./ep22/tx_request_queue
./ep23
./ep23/descriptor_fetch_queue
./ep23/event_queue
./ep23/info_queue
./ep23/protocol_status_queue
./ep23/request_queue
./ep23/rx_fifo
./ep23/rx_request_queue
./ep23/tx_fifo
./ep23/tx_request_queue
./ep24
./ep24/descriptor_fetch_queue
./ep24/event_queue
./ep24/info_queue
./ep24/protocol_status_queue
./ep24/request_queue
./ep24/rx_fifo
./ep24/rx_request_queue
./ep24/tx_fifo
./ep24/tx_request_queue
./ep25
./ep25/descriptor_fetch_queue
./ep25/event_queue
./ep25/info_queue
./ep25/protocol_status_queue
./ep25/request_queue
./ep25/rx_fifo
./ep25/rx_request_queue
./ep25/tx_fifo
./ep25/tx_request_queue
./ep26
./ep26/descriptor_fetch_queue
./ep26/event_queue
./ep26/info_queue
./ep26/protocol_status_queue
./ep26/request_queue
./ep26/rx_fifo
./ep26/rx_request_queue
./ep26/tx_fifo
./ep26/tx_request_queue
./ep27
./ep27/descriptor_fetch_queue
./ep27/event_queue
./ep27/info_queue
./ep27/protocol_status_queue
./ep27/request_queue
./ep27/rx_fifo
./ep27/rx_request_queue
./ep27/tx_fifo
./ep27/tx_request_queue
./ep28
./ep28/descriptor_fetch_queue
./ep28/event_queue
./ep28/info_queue
./ep28/protocol_status_queue
./ep28/request_queue
./ep28/rx_fifo
./ep28/rx_request_queue
./ep28/tx_fifo
./ep28/tx_request_queue
./ep29
./ep29/descriptor_fetch_queue
./ep29/event_queue
./ep29/info_queue
./ep29/protocol_status_queue
./ep29/request_queue
./ep29/rx_fifo
./ep29/rx_request_queue
./ep29/tx_fifo
./ep29/tx_request_queue
./ep2/descriptor_fetch_queue
./ep2/event_queue
./ep2/info_queue
./ep2/protocol_status_queue
./ep2/request_queue
./ep2/rx_fifo
./ep2/rx_request_queue
./ep2/tx_fifo
./ep2/tx_request_queue
./ep3
./ep30
./ep30/descriptor_fetch_queue
./ep30/event_queue
./ep30/info_queue
./ep30/protocol_status_queue
./ep30/request_queue
./ep30/rx_fifo
./ep30/rx_request_queue
./ep30/tx_fifo
./ep30/tx_request_queue
./ep31
./ep31/descriptor_fetch_queue
./ep31/event_queue
./ep31/info_queue
./ep31/protocol_status_queue
./ep31/request_queue
./ep31/rx_fifo
./ep31/rx_request_queue
./ep31/tx_fifo
./ep31/tx_request_queue
./ep3/descriptor_fetch_queue
./ep3/event_queue
./ep3/info_queue
./ep3/protocol_status_queue
./ep3/request_queue
./ep3/rx_fifo
./ep3/rx_request_queue
./ep3/tx_fifo
./ep3/tx_request_queue
./ep4
./ep4/descriptor_fetch_queue
./ep4/event_queue
./ep4/info_queue
./ep4/protocol_status_queue
./ep4/request_queue
./ep4/rx_fifo
./ep4/rx_request_queue
./ep4/tx_fifo
./ep4/tx_request_queue
./ep5
./ep5/descriptor_fetch_queue
./ep5/event_queue
./ep5/info_queue
./ep5/protocol_status_queue
./ep5/request_queue
./ep5/rx_fifo
./ep5/rx_request_queue
./ep5/tx_fifo
./ep5/tx_request_queue
./ep6
./ep6/descriptor_fetch_queue
./ep6/event_queue
./ep6/info_queue
./ep6/protocol_status_queue
./ep6/request_queue
./ep6/rx_fifo
./ep6/rx_request_queue
./ep6/tx_fifo
./ep6/tx_request_queue
./ep7
./ep7/descriptor_fetch_queue
./ep7/event_queue
./ep7/info_queue
./ep7/protocol_status_queue
./ep7/request_queue
./ep7/rx_fifo
./ep7/rx_request_queue
./ep7/tx_fifo
./ep7/tx_request_queue
./ep8
./ep8/descriptor_fetch_queue
./ep8/event_queue
./ep8/info_queue
./ep8/protocol_status_queue
./ep8/request_queue
./ep8/rx_fifo
./ep8/rx_request_queue
./ep8/tx_fifo
./ep8/tx_request_queue
./ep9
./ep9/descriptor_fetch_queue
./ep9/event_queue
./ep9/info_queue
./ep9/protocol_status_queue
./ep9/request_queue
./ep9/rx_fifo
./ep9/rx_request_queue
./ep9/tx_fifo
./ep9/tx_request_queue
./link_state
./mode
./regdump
./testmode

--
balbi

#25 lore raw

Hi,

Quoted 5 lines · Changbin

Hi, Balbi.

Feel free to change it, I may not have enough time on this currently. "per-endpoint directory" is great idea, then we do not need find out wanted info from one big file, but just go to specific dir.

that was the idea, glad you liked it ;-)

Quoted 1 line

Btw, I'd mention that not all out ep has a rx fifo. So in my original patch,

yeah, rx fifos are dynamically allocated by the HW itself, AFAICT.

Quoted 7 lines

not all FIFO/Queue info are valid. We need pick out the real info we need. And I didn't find any method to read the FIFO map.

At last, comparing with the FIFO/Queue info, I think software transfer Requests list, TRBs info, EVENTs history are much more useful for debugging the driver. If you can also add these info to each EP folder, that is awesome! :)

I'll think about adding these but for the lifetime of requests and trbs and events, etc, we have tracepoints for that. I usually do the following when debugging:

# mount -t debugfs none /sys/kernel/debug
# cd /sys/kernel/debug/tracing
# echo 2048 > buffer_size_kb
# echo 1 > events/dwc3/enable

(do something to break it)

# cp trace /mnt/sdcard # or something like that

then read the file. You can make it as large or as small as you like (given some constraints, of course ;-) but I've had no issues allocating 128MiB in the past.

Signature · 1 line
balbi
#26 lore raw
Quoted 17 lines
Quoted 2 lines

At last, comparing with the FIFO/Queue info, I think software transfer Requests list, TRBs info, EVENTs history are much more useful for

debugging

Quoted 2 lines

the driver. If you can also add these info to each EP folder, that is awesome! :)

I'll think about adding these but for the lifetime of requests and trbs and events, etc, we have tracepoints for that. I usually do the following when debugging:

# mount -t debugfs none /sys/kernel/debug
# cd /sys/kernel/debug/tracing
# echo 2048 > buffer_size_kb
# echo 1 > events/dwc3/enable

(do something to break it)

Quoted 8 lines
# cp trace /mnt/sdcard # or something like that

then read the file. You can make it as large or as small as you like (given some constraints, of course ;-) but I've had no issues allocating 128MiB in the past.

--
Balbi

Thanks for the sharing, this is a good approach to capture dynamic behaviors. But a dump of current state has below advantages:
1. a quick view for the pending transfers. Then we can quickly checking the transfer status.
2. no side-effect. This is important in some case. We usually encounter some transfer issues but very hard to reproduce it. But we cannot enable trace all the time since performance concern. Then I thought it was so great if I can have a look for the trb status. :)

Best Regards,
Du, Changbin

#27 lore raw

Hi,

Quoted 26 lines · Changbin
Quoted 17 lines
Quoted 2 lines

At last, comparing with the FIFO/Queue info, I think software transfer Requests list, TRBs info, EVENTs history are much more useful for

debugging

Quoted 2 lines

the driver. If you can also add these info to each EP folder, that is awesome! :)

I'll think about adding these but for the lifetime of requests and trbs and events, etc, we have tracepoints for that. I usually do the following when debugging:

# mount -t debugfs none /sys/kernel/debug
# cd /sys/kernel/debug/tracing
# echo 2048 > buffer_size_kb
# echo 1 > events/dwc3/enable

(do something to break it)

Quoted 8 lines
# cp trace /mnt/sdcard # or something like that

then read the file. You can make it as large or as small as you like (given some constraints, of course ;-) but I've had no issues allocating 128MiB in the past.

--
Balbi

Quoted 9 lines

Thanks for the sharing, this is a good approach to capture dynamic behaviors. But a dump of current state has below advantages:
1. a quick view for the pending transfers. Then we can quickly checking the transfer status.
2. no side-effect. This is important in some case. We usually encounter some transfer issues but very hard to reproduce it. But we cannot enable trace all the time since performance concern. Then I thought it was so great if I can have a look for the trb status. :)

yeah, okay. We can definitely add "current state" of almost anything, but if you need history, then debugfs is not the best interface and I'd point you to tracepoints ;-)

I'll think about how I can add TRB state, seems like we'd need to dump the entire endpoint ring, and that's 256 TRBs per endpoint :-p Then we also need to know endpoint's dequeue and enqueue pointer. Oh well, let me get this first setup of files out of the way, then we can add more later much more easily.

Signature · 1 line
balbi
#28 lore raw
Quoted 44 lines

Hi,

Quoted 4 lines · Changbin
Quoted 4 lines
Quoted 2 lines

At last, comparing with the FIFO/Queue info, I think software transfer Requests list, TRBs info, EVENTs history are much more useful for

debugging

Quoted 1 line

the driver. If you can also add these info to each EP folder, that is

awesome!

Quoted 22 lines
Quoted 13 lines
Quoted 1 line

:)

I'll think about adding these but for the lifetime of requests and trbs and events, etc, we have tracepoints for that. I usually do the following when debugging:

# mount -t debugfs none /sys/kernel/debug
# cd /sys/kernel/debug/tracing
# echo 2048 > buffer_size_kb
# echo 1 > events/dwc3/enable

(do something to break it)

Quoted 8 lines
# cp trace /mnt/sdcard # or something like that

then read the file. You can make it as large or as small as you like (given some constraints, of course ;-) but I've had no issues allocating 128MiB in the past.

--
Balbi

Quoted 9 lines

Thanks for the sharing, this is a good approach to capture dynamic behaviors. But a dump of current state has below advantages:
1. a quick view for the pending transfers. Then we can quickly checking the transfer status.
2. no side-effect. This is important in some case. We usually encounter some transfer issues but very hard to reproduce it. But we cannot enable trace all the time since performance concern. Then I thought it was so great if I can have a look for the trb status. :)

yeah, okay. We can definitely add "current state" of almost anything, but if you need history, then debugfs is not the best interface and I'd point you to tracepoints ;-)

Quoted 8 lines

I'll think about how I can add TRB state, seems like we'd need to dump the entire endpoint ring, and that's 256 TRBs per endpoint :-p Then we also need to know endpoint's dequeue and enqueue pointer. Oh well, let me get this first setup of files out of the way, then we can add more later much more easily.

--
Balbi

Okay, things need finish step by step. Thank you, Balbi. ( ゜- ゜)つロ

Best Regards,
Du, Changbin

#29 lore raw

PATCH v3 2/2 usb: dwc3: add debugfs node to dump FIFO/Queue available space

In reply to [email protected]

From: "Du, Changbin" <[email protected]>

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.

---
changes from v2:
no changes

---
 drivers/usb/dwc3/core.h    |  5 +++++
 drivers/usb/dwc3/debugfs.c | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
drivers/usb/dwc3/core.h +5 -0
index 6254b2f..899cf76 100644
@@ -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
drivers/usb/dwc3/debugfs.c +40 -0
index 071b286..02eaf54 100644
@@ -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;
@@ -639,6 +678,7 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
 	dwc->regset->base = dwc->regs;
 
 	debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
+	debugfs_create_file("fifo", S_IRUGO, root, dwc, &dwc3_fifo_fops);
 
 	if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE))
 		debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
Signature · 1 line
2.5.0