2016-04-06 08:38:32

by Du, Changbin

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Du, Changbin <[email protected]>
---
drivers/usb/dwc3/core.h | 5 +++++
drivers/usb/dwc3/debugfs.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 50 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 9ac37fe..f9a8d9e 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;
@@ -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;
+ goto err1;
+ }
+
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


2016-04-06 09:25:15

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] usb: dwc3: add debugfs node to dump FIFO/Queue available space

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.
>
> Signed-off-by: Du, Changbin <[email protected]>
> ---
> 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?



>
> 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 9ac37fe..f9a8d9e 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;
> @@ -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

2016-04-06 11:38:26

by Du, Changbin

[permalink] [raw]
Subject: RE: [PATCH] usb: dwc3: add debugfs node 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 <[email protected]>
> > ---
> > 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?
>
Just forget it :)

> > static int dwc3_testmode_show(struct seq_file *s, void *unused)
> > {
> > 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);
> > + 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

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

2016-04-06 12:29:25

by Felipe Balbi

[permalink] [raw]
Subject: RE: [PATCH] usb: dwc3: add debugfs node to dump FIFO/Queue available space


Hi,

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

"Du, Changbin" <[email protected]> writes:
>> > @@ -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
>
> Agree with you. I will create another patch to cleanup this piece of
> code.

cool, thanks

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

good catch, thanks for fixing it.

--
balbi


Attachments:
signature.asc (818.00 B)

2016-04-06 15:54:52

by Du, Changbin

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

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(-)

--
2.5.0

2016-04-06 15:54:56

by Du, Changbin

[permalink] [raw]
Subject: [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.

Signed-off-by: Du, Changbin <[email protected]>
---
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(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 17fd814..30f825c 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -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);

diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index 07fbc2d..71e3180 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -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
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 9ac37fe..071b286 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -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;
- 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;

dwc->root = root;

dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL);
if (!dwc->regset) {
- ret = -ENOMEM;
- goto err1;
+ debugfs_remove_recursive(root);
+ return;
}

dwc->regset->regs = dwc3_regs;
dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
dwc->regset->base = dwc->regs;

- file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
- if (!file) {
- ret = -ENOMEM;
- goto err1;
- }
+ debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);

- if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
- file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
+ if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE))
+ debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
dwc, &dwc3_mode_fops);
- if (!file) {
- ret = -ENOMEM;
- goto err1;
- }
- }

if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) ||
IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
- file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
+ debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
dwc, &dwc3_testmode_fops);
- if (!file) {
- ret = -ENOMEM;
- goto err1;
- }
-
- file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
+ debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
dwc, &dwc3_link_state_fops);
- if (!file) {
- ret = -ENOMEM;
- goto err1;
- }
}
-
- return 0;
-
-err1:
- debugfs_remove_recursive(root);
-
-err0:
- return ret;
}

void dwc3_debugfs_exit(struct dwc3 *dwc)
--
2.5.0

2016-04-06 15:54:58

by Du, Changbin

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

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

Signed-off-by: Du, Changbin <[email protected]>
---
drivers/usb/dwc3/debugfs.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 071b286..2d4f397 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -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;
}
--
2.5.0

2016-04-06 15:56:09

by Du, Changbin

[permalink] [raw]
Subject: [PATCH v2 3/3] 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.

Signed-off-by: Du, Changbin <[email protected]>
---
drivers/usb/dwc3/core.h | 5 +++++
drivers/usb/dwc3/debugfs.c | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 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 2d4f397..bb608e0 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;
@@ -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,
--
2.5.0

2016-04-06 21:08:20

by Greg Kroah-Hartman

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

On Wed, Apr 06, 2016 at 11:44:05PM +0800, [email protected] wrote:
> From: "Du, Changbin" <[email protected]>
>
> Signed-off-by: Du, Changbin <[email protected]>
> ---

You need a changelog entry in order for a patch to be able to be
accepted.

thanks,

greg k-h

2016-04-07 05:07:23

by Felipe Balbi

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


Hi,

before I review your patches, one comment

[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

> 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.

--
balbi


Attachments:
signature.asc (818.00 B)

2016-04-07 05:07:44

by Felipe Balbi

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

[email protected] writes:

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

no commit log == no commit, sorry

> Signed-off-by: Du, Changbin <[email protected]>
> ---
> drivers/usb/dwc3/debugfs.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
> index 071b286..2d4f397 100644
> --- a/drivers/usb/dwc3/debugfs.c
> +++ b/drivers/usb/dwc3/debugfs.c
> @@ -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;
> }
> --
> 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

--
balbi


Attachments:
signature.asc (818.00 B)

2016-04-07 05:21:35

by Du, Changbin

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

> before I review your patches, one comment
>
> [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
>
> > 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.
>
> --
> 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

2016-04-07 05:24:29

by Felipe Balbi

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


HI

"Du, Changbin" <[email protected]> writes:
>> before I review your patches, one comment
>>
>> [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
>>
>> > 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.
>>
>> --
>> 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 ;-)

--
balbi


Attachments:
signature.asc (818.00 B)

2016-04-08 09:45:37

by Du, Changbin

[permalink] [raw]
Subject: [PATCH v3 0/2] 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.

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(-)

--
2.5.0

2016-04-08 09:45:39

by Du, Changbin

[permalink] [raw]
Subject: [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.

Signed-off-by: Du, Changbin <[email protected]>
---
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(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 17fd814..30f825c 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -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);

diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index 07fbc2d..71e3180 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -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
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 9ac37fe..071b286 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -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;
- 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;

dwc->root = root;

dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL);
if (!dwc->regset) {
- ret = -ENOMEM;
- goto err1;
+ debugfs_remove_recursive(root);
+ return;
}

dwc->regset->regs = dwc3_regs;
dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
dwc->regset->base = dwc->regs;

- file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
- if (!file) {
- ret = -ENOMEM;
- goto err1;
- }
+ debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);

- if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
- file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
+ if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE))
+ debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
dwc, &dwc3_mode_fops);
- if (!file) {
- ret = -ENOMEM;
- goto err1;
- }
- }

if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) ||
IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
- file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
+ debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
dwc, &dwc3_testmode_fops);
- if (!file) {
- ret = -ENOMEM;
- goto err1;
- }
-
- file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
+ debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
dwc, &dwc3_link_state_fops);
- if (!file) {
- ret = -ENOMEM;
- goto err1;
- }
}
-
- return 0;
-
-err1:
- debugfs_remove_recursive(root);
-
-err0:
- return ret;
}

void dwc3_debugfs_exit(struct dwc3 *dwc)
--
2.5.0

2016-04-08 09:45:42

by Du, Changbin

[permalink] [raw]
Subject: [PATCH v3 2/2] 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.

Signed-off-by: Du, Changbin <[email protected]>
---
changes from v2:
no changes

---
drivers/usb/dwc3/core.h | 5 +++++
drivers/usb/dwc3/debugfs.c | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 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 071b286..02eaf54 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;
@@ -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,
--
2.5.0

2016-04-11 08:16:33

by Felipe Balbi

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


Hi,

[email protected] writes:
> diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
> index 07fbc2d..71e3180 100644
> --- a/drivers/usb/dwc3/debug.h
> +++ b/drivers/usb/dwc3/debug.h
> @@ -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
> diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
> index 9ac37fe..071b286 100644
> --- a/drivers/usb/dwc3/debugfs.c
> +++ b/drivers/usb/dwc3/debugfs.c
> @@ -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;
> - 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.

> 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);


--
balbi


Attachments:
signature.asc (818.00 B)

2016-04-11 11:19:18

by Du, Changbin

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

> > 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.
>
Balbi, so you mean we should not let the failure go silent, right?

> > 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);
>
>
> --
> 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

2016-04-11 11:25:20

by Felipe Balbi

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


Hi,

"Du, Changbin" <[email protected]> writes:
>> > 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.
>>
> 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() ;-)

>> > 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);
>>
>>
>> --
>> Balbi
>
> No, no need anymore. Because no branch share this code now.
> Then remove the goto would make code a little clear.

fair enough.

--
balbi


Attachments:
signature.asc (818.00 B)

2016-04-12 11:21:18

by Du, Changbin

[permalink] [raw]
Subject: [PATCH v4 0/2] 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(-)

--
2.5.0

2016-04-12 11:21:20

by Du, Changbin

[permalink] [raw]
Subject: [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.

Signed-off-by: Du, Changbin <[email protected]>
---
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(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 17fd814..30f825c 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -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);

diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index 07fbc2d..71e3180 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -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
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 9ac37fe..615d4dc 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -618,24 +618,24 @@ 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;
- struct dentry *file;
- int ret;
+ struct dentry *file;

root = debugfs_create_dir(dev_name(dwc->dev), NULL);
- if (!root) {
- ret = -ENOMEM;
- goto err0;
+ if (IS_ERR_OR_NULL(root)) {
+ if (!root)
+ dev_err(dwc->dev, "Can't create debugfs root\n");
+ return;
}
-
dwc->root = root;

dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL);
if (!dwc->regset) {
- ret = -ENOMEM;
- goto err1;
+ dev_err(dwc->dev, "Failed to alloc regset\n");
+ debugfs_remove_recursive(root);
+ return;
}

dwc->regset->regs = dwc3_regs;
@@ -643,44 +643,28 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
dwc->regset->base = dwc->regs;

file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
- if (!file) {
- ret = -ENOMEM;
- goto err1;
- }
+ if (!file)
+ dev_err(dwc->dev, "Can't create debugfs regdump\n");

if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
dwc, &dwc3_mode_fops);
- if (!file) {
- ret = -ENOMEM;
- goto err1;
- }
+ if (!file)
+ dev_err(dwc->dev, "Can't create debugfs mode\n");
}

if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) ||
IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
dwc, &dwc3_testmode_fops);
- if (!file) {
- ret = -ENOMEM;
- goto err1;
- }
-
- file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
- dwc, &dwc3_link_state_fops);
- if (!file) {
- ret = -ENOMEM;
- goto err1;
- }
- }
+ if (!file)
+ dev_err(dwc->dev, "Can't create debugfs testmode\n");

- return 0;
-
-err1:
- debugfs_remove_recursive(root);
-
-err0:
- return ret;
+ file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR,
+ root, dwc, &dwc3_link_state_fops);
+ if (!file)
+ dev_err(dwc->dev, "Can't create debugfs link_state\n");
+ }
}

void dwc3_debugfs_exit(struct dwc3 *dwc)
--
2.5.0

2016-04-12 11:21:24

by Du, Changbin

[permalink] [raw]
Subject: [PATCH v4 2/2] 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.

Signed-off-by: Du, Changbin <[email protected]>
---
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

2016-04-12 12:58:14

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH v4 2/2] usb: dwc3: add debugfs node to dump FIFO/Queue available space

Hello.

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 (.

> 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 <[email protected]>
> ---
> v4:
> Do not fail silently, but print error.
[...]
> 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
[...]
> @@ -642,10 +681,15 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
> dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
> dwc->regset->base = dwc->regs;
>
> +

Why?

> 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

2016-04-14 03:27:26

by Du, Changbin

[permalink] [raw]
Subject: RE: [PATCH v4 2/2] usb: dwc3: add debugfs node to dump FIFO/Queue available space

Hello, Sergei,
> > 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.

>
> > 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 <[email protected]>
> > ---
> > v4:
> > Do not fail silently, but print error.
> [...]
> > 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
> [...]
> > @@ -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.

>
> > 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

2016-04-14 08:05:10

by Felipe Balbi

[permalink] [raw]
Subject: Re: [PATCH v4 2/2] usb: dwc3: add debugfs node to dump FIFO/Queue available space


Hi,

[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.
>
> Signed-off-by: Du, Changbin <[email protected]>
> ---
> 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)

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

> 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)

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.

> +{
> + 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) ??

> + 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

> + 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


Attachments:
signature.asc (818.00 B)

2016-04-14 11:15:58

by Du, Changbin

[permalink] [raw]
Subject: RE: [PATCH v4 2/2] usb: dwc3: add debugfs node to dump FIFO/Queue available space

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

> -----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,
>
> [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.
> >
> > Signed-off-by: Du, Changbin <[email protected]>
> > ---
> > 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)
>
> 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
>
> > 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)
>
> 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.
>
> > +{
> > + 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) ??
>
> > + 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
>
> > + 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

2016-04-14 11:20:44

by Felipe Balbi

[permalink] [raw]
Subject: RE: [PATCH v4 2/2] usb: dwc3: add debugfs node to dump FIFO/Queue available space


Hi,

"Du, Changbin" <[email protected]> writes:
> 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 ;-)

> 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.

> 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.

--
balbi


Attachments:
signature.asc (818.00 B)

2016-04-14 11:37:26

by Du, Changbin

[permalink] [raw]
Subject: RE: [PATCH v4 2/2] usb: dwc3: add debugfs node to dump FIFO/Queue available space

> > 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.
>
> --
> 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

2016-04-14 11:43:47

by Felipe Balbi

[permalink] [raw]
Subject: RE: [PATCH v4 2/2] usb: dwc3: add debugfs node to dump FIFO/Queue available space


Hi,

"Du, Changbin" <[email protected]> writes:
>> > 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.
>>
>> --
>> 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. :)

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.

--
balbi


Attachments:
signature.asc (818.00 B)

2016-04-14 11:59:06

by Du, Changbin

[permalink] [raw]
Subject: RE: [PATCH v4 2/2] usb: dwc3: add debugfs node to dump FIFO/Queue available space

> Hi,
>
> "Du, Changbin" <[email protected]> writes:
> >> > 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.
> >>
> >> --
> >> 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. :)
>
> 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.
>
> --
> Balbi

Okay, things need finish step by step. Thank you, Balbi. ( ?b- ?b)?ĥ?

Best Regards,
Du, Changbin