usb: xhci: add debugfs support for ep with stream
Subsystems (2)
PATCH 1/1 usb: xhci: add debugfs support for ep with stream
To show the trb ring of streams, use the exsiting ring files of bulk ep to show trb ring of one specific stream ID, which stream ID's trb ring will be shown, is controlled by a new debugfs file stream_id, this is to avoid to create a large number of dir for every allocate stream IDs, another debugfs file stream_context_array is created to show all the allocated stream context array entries.
--- drivers/usb/host/xhci-debugfs.c | 117 +++++++++++++++++++++++++++++++++++++++- drivers/usb/host/xhci-debugfs.h | 19 +++++++ drivers/usb/host/xhci-mem.c | 4 +- drivers/usb/host/xhci.c | 4 ++ 4 files changed, 142 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-debugfs.c +116 -1
@@ -450,9 +450,10 @@ void xhci_debugfs_create_endpoint(struct xhci_hcd *xhci,if (!epriv)return ; + epriv->show_ring = dev->eps[ep_index].ring;snprintf (epriv->name,sizeof (epriv->name),"ep%02d" , ep_index); epriv->root =xhci_debugfs_create_ring_dir (xhci, - &dev->eps[ep_index].ring, + &epriv->show_ring, epriv->name, spriv->root); spriv->eps[ep_index] = epriv;
@@ -474,6 +475,120 @@ void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci,kfree (epriv); } +static int xhci_stream_id_show (struct seq_file *s,void *unused) +{ +struct xhci_ep_priv *epriv = s->private; + +seq_printf (s,"Supported stream IDs are 1 ~ %d, trb ring to be shown is for stream id %d\n" , + epriv->stream_info->num_streams -1 , epriv->stream_id); + +return 0 ; +} + +static int xhci_stream_id_open (struct inode *inode,struct file *file) +{ +return single_open (file, xhci_stream_id_show, inode->i_private); +} + +static ssize_t xhci_stream_id_write (struct file *file,const char __user *ubuf, +size_t count,loff_t *ppos) +{ +struct seq_file *s = file->private_data; +struct xhci_ep_priv *epriv = s->private; +int ret; +u16 stream_id;/* MaxPStreams + 1 <= 16 */ + +/* Decimal number */ + ret =kstrtou16_from_user (ubuf, count,10 , &stream_id); +if (ret) +return ret; + +if (stream_id ==0 || stream_id >= epriv->stream_info->num_streams) +return -EINVAL ; + + epriv->stream_id = stream_id; + epriv->show_ring = epriv->stream_info->stream_rings[stream_id]; + +return count; +} + +static const struct file_operations stream_id_fops = { + .open = xhci_stream_id_open, + .write = xhci_stream_id_write, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int xhci_stream_context_array_show (struct seq_file *s,void *unused) +{ +struct xhci_ep_priv *epriv = s->private; +struct xhci_stream_ctx *stream_ctx; +dma_addr_t dma; +int id; + +seq_printf (s,"Allocated %d streams and %d stream context array entries\n" , + epriv->stream_info->num_streams, + epriv->stream_info->num_stream_ctxs); + +for (id =0 ; id < epriv->stream_info->num_stream_ctxs; id++) { + stream_ctx = epriv->stream_info->stream_ctx_array + id; + dma = epriv->stream_info->ctx_array_dma + id *16 ; +if (id < epriv->stream_info->num_streams) +seq_printf (s,"%pad stream id %d deq %016llx\n" , &dma, id, +le64_to_cpu (stream_ctx->stream_ring)); +else +seq_printf (s,"%pad stream context entry not used deq %016llx\n" , + &dma,le64_to_cpu (stream_ctx->stream_ring)); + } + +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (xhci_stream_context_array); + +void xhci_debugfs_create_stream_files (struct xhci_hcd *xhci, +struct xhci_virt_device *dev, +int ep_index) +{ +struct xhci_slot_priv *spriv = dev->debugfs_private; +struct xhci_ep_priv *epriv; + +if (!spriv || !spriv->eps[ep_index] || + !dev->eps[ep_index].stream_info) +return ; + + epriv = spriv->eps[ep_index]; + epriv->stream_info = dev->eps[ep_index].stream_info; + +/* Show trb ring of stream ID 1 by default */ + epriv->stream_id =1 ; + epriv->show_ring = epriv->stream_info->stream_rings[1 ]; + epriv->stream_ctx_dentry =debugfs_create_file ("stream_context_array" , +0444 , epriv->root, epriv, + &xhci_stream_context_array_fops); + + epriv->stream_id_dentry =debugfs_create_file ("stream_id" ,0644 , + epriv->root, epriv, + &stream_id_fops); +} + +void xhci_debugfs_remove_stream_files (struct xhci_hcd *xhci, +struct xhci_virt_device *dev, +int ep_index) +{ +struct xhci_slot_priv *spriv = dev->debugfs_private; +struct xhci_ep_priv *epriv; + +if (!spriv || !spriv->eps[ep_index] || + !dev->eps[ep_index].stream_info) +return ; + + epriv = spriv->eps[ep_index]; + epriv->show_ring = dev->eps[ep_index].ring; +debugfs_remove (epriv->stream_ctx_dentry); +debugfs_remove (epriv->stream_id_dentry); +} +void xhci_debugfs_create_slot (struct xhci_hcd *xhci,int slot_id) {struct xhci_slot_priv *priv;
drivers/usb/host/xhci-debugfs.h +19 -0
@@ -91,6 +91,11 @@ struct xhci_file_map {struct xhci_ep_priv {char name[DEBUGFS_NAMELEN ];struct dentry *root; +struct dentry *stream_ctx_dentry; +struct dentry *stream_id_dentry; +struct xhci_stream_info *stream_info; +struct xhci_ring *show_ring; +unsigned int stream_id; };struct xhci_slot_priv {
@@ -113,6 +118,12 @@ void xhci_debugfs_create_endpoint(struct xhci_hcd *xhci,void xhci_debugfs_remove_endpoint (struct xhci_hcd *xhci,struct xhci_virt_device *virt_dev,int ep_index); +void xhci_debugfs_create_stream_files (struct xhci_hcd *xhci, +struct xhci_virt_device *virt_dev, +int ep_index); +void xhci_debugfs_remove_stream_files (struct xhci_hcd *xhci, +struct xhci_virt_device *virt_dev, +int ep_index);#else static inline void xhci_debugfs_init (struct xhci_hcd *xhci) { }static inline void xhci_debugfs_exit (struct xhci_hcd *xhci) { }
@@ -128,6 +139,14 @@ static inline void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, int ep_index) { } +static inline void +xhci_debugfs_create_steam_files(struct xhci_hcd *xhci, + struct xhci_virt_device *virt_dev, + int ep_index) { } +static inline void +xhci_debugfs_remove_stream_files(struct xhci_hcd *xhci, + struct xhci_virt_device *virt_dev, + int ep_index) { }#endif /* CONFIG_DEBUG_FS */ #endif /* __LINUX_XHCI_DEBUGFS_H */
drivers/usb/host/xhci-mem.c +3 -1
@@ -898,9 +898,11 @@ void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id)for (i =0 ; i <31 ; i++) {if (dev->eps[i].ring)xhci_ring_free (xhci, dev->eps[i].ring); -if (dev->eps[i].stream_info) +if (dev->eps[i].stream_info) {xhci_free_stream_info (xhci, dev->eps[i].stream_info); +xhci_debugfs_remove_stream_files (xhci, dev, i); + }/* Endpoints on the TT/root port lists should have been removed * when usb_disable_device() was called for the device. * We can't drop them anyway, because the udev might have gone
drivers/usb/host/xhci.c +4 -0
@@ -2846,6 +2846,7 @@ static void xhci_check_bw_drop_ep_streams(struct xhci_hcd *xhci,xhci_free_stream_info (xhci, ep->stream_info); ep->stream_info =NULL ; ep->ep_state &= ~EP_HAS_STREAMS ; +xhci_debugfs_remove_stream_files (xhci, vdev, i); } }
@@ -3529,6 +3530,7 @@ static int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,xhci_dbg (xhci,"Slot %u ep ctx %u now has streams.\n" , udev->slot_id, ep_index); vdev->eps[ep_index].ep_state |=EP_HAS_STREAMS ; +xhci_debugfs_create_stream_files (xhci, vdev, ep_index); }xhci_free_command (xhci, config_cmd);spin_unlock_irqrestore (&xhci->lock, flags);
@@ -3638,6 +3640,7 @@ static int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,*/ vdev->eps[ep_index].ep_state &= ~EP_GETTING_NO_STREAMS ; vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS ; +xhci_debugfs_remove_stream_files (xhci, vdev, ep_index); }spin_unlock_irqrestore (&xhci->lock, flags);
@@ -3823,6 +3826,7 @@ static int xhci_discover_or_reset_device(struct usb_hcd *hcd,xhci_free_stream_info (xhci, ep->stream_info); ep->stream_info =NULL ; ep->ep_state &= ~EP_HAS_STREAMS ; +xhci_debugfs_remove_stream_files (xhci, virt_dev, i); }if (ep->ring) {
Signature · 1 line
2.7.4
Greg KH
maintainerQuoted 120 lines · Li Jun
To show the trb ring of streams, use the exsiting ring files of bulk ep to show trb ring of one specific stream ID, which stream ID's trb ring will be shown, is controlled by a new debugfs file
stream_id, this is to avoid to create a large number of dir for every allocate stream IDs, another debugfs filestream_context_arrayis created to show all the allocated stream context array entries.Signed-off-by Li Jun <[email protected]>--- drivers/usb/host/xhci-debugfs.c | 117 +++++++++++++++++++++++++++++++++++++++- drivers/usb/host/xhci-debugfs.h | 19 +++++++ drivers/usb/host/xhci-mem.c | 4 +- drivers/usb/host/xhci.c | 4 ++ 4 files changed, 142 insertions(+), 2 deletions(-)drivers/usb/host/xhci-debugfs.c +87
-1@@ -450,9 +450,10 @@ void xhci_debugfs_create_endpoint(struct xhci_hcd *xhci,if (!epriv)return ; + epriv->show_ring = dev->eps[ep_index].ring;snprintf (epriv->name,sizeof (epriv->name),"ep%02d" , ep_index); epriv->root =xhci_debugfs_create_ring_dir (xhci, - &dev->eps[ep_index].ring, + &epriv->show_ring, epriv->name, spriv->root); spriv->eps[ep_index] = epriv;@@ -474,6 +475,120 @@ void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci,kfree (epriv); } +static int xhci_stream_id_show (struct seq_file *s,void *unused) +{ +struct xhci_ep_priv *epriv = s->private; + +seq_printf (s,"Supported stream IDs are 1 ~ %d, trb ring to be shown is for stream id %d\n" , + epriv->stream_info->num_streams -1 , epriv->stream_id); + +return 0 ; +} + +static int xhci_stream_id_open (struct inode *inode,struct file *file) +{ +return single_open (file, xhci_stream_id_show, inode->i_private); +} + +static ssize_t xhci_stream_id_write (struct file *file,const char __user *ubuf, +size_t count,loff_t *ppos) +{ +struct seq_file *s = file->private_data; +struct xhci_ep_priv *epriv = s->private; +int ret; +u16 stream_id;/* MaxPStreams + 1 <= 16 */ + +/* Decimal number */ + ret =kstrtou16_from_user (ubuf, count,10 , &stream_id); +if (ret) +return ret; + +if (stream_id ==0 || stream_id >= epriv->stream_info->num_streams) +return -EINVAL ; + + epriv->stream_id = stream_id; + epriv->show_ring = epriv->stream_info->stream_rings[stream_id]; + +return count; +} + +static const struct file_operations stream_id_fops = { + .open = xhci_stream_id_open, + .write = xhci_stream_id_write, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int xhci_stream_context_array_show (struct seq_file *s,void *unused) +{ +struct xhci_ep_priv *epriv = s->private; +struct xhci_stream_ctx *stream_ctx; +dma_addr_t dma; +int id; + +seq_printf (s,"Allocated %d streams and %d stream context array entries\n" , + epriv->stream_info->num_streams, + epriv->stream_info->num_stream_ctxs); + +for (id =0 ; id < epriv->stream_info->num_stream_ctxs; id++) { + stream_ctx = epriv->stream_info->stream_ctx_array + id; + dma = epriv->stream_info->ctx_array_dma + id *16 ; +if (id < epriv->stream_info->num_streams) +seq_printf (s,"%pad stream id %d deq %016llx\n" , &dma, id, +le64_to_cpu (stream_ctx->stream_ring)); +else +seq_printf (s,"%pad stream context entry not used deq %016llx\n" , + &dma,le64_to_cpu (stream_ctx->stream_ring)); + } + +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (xhci_stream_context_array); + +void xhci_debugfs_create_stream_files (struct xhci_hcd *xhci, +struct xhci_virt_device *dev, +int ep_index) +{ +struct xhci_slot_priv *spriv = dev->debugfs_private; +struct xhci_ep_priv *epriv; + +if (!spriv || !spriv->eps[ep_index] || + !dev->eps[ep_index].stream_info) +return ; + + epriv = spriv->eps[ep_index]; + epriv->stream_info = dev->eps[ep_index].stream_info; +
drivers/usb/host/xhci-debugfs.c void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci, · line 572
Quoted 10 lines
drivers/usb/host/xhci-debugfs.c +10
-0+/* Show trb ring of stream ID 1 by default */ + epriv->stream_id =1 ; + epriv->show_ring = epriv->stream_info->stream_rings[1 ]; + epriv->stream_ctx_dentry =debugfs_create_file ("stream_context_array" , +0444 , epriv->root, epriv, + &xhci_stream_context_array_fops); + + epriv->stream_id_dentry =debugfs_create_file ("stream_id" ,0644 , + epriv->root, epriv, + &stream_id_fops);
Do you really need to save these files off, or could you use 'debug_remove_recursive()' to remove them all when the device goes away?
Quoted 27 lines
drivers/usb/host/xhci-debugfs.c +19
-0+} + +void xhci_debugfs_remove_stream_files (struct xhci_hcd *xhci, +struct xhci_virt_device *dev, +int ep_index) +{ +struct xhci_slot_priv *spriv = dev->debugfs_private; +struct xhci_ep_priv *epriv; + +if (!spriv || !spriv->eps[ep_index] || + !dev->eps[ep_index].stream_info) +return ; + + epriv = spriv->eps[ep_index]; + epriv->show_ring = dev->eps[ep_index].ring; +debugfs_remove (epriv->stream_ctx_dentry); +debugfs_remove (epriv->stream_id_dentry); +} +void xhci_debugfs_create_slot (struct xhci_hcd *xhci,int slot_id) {struct xhci_slot_priv *priv;drivers/usb/host/xhci-debugfs.h +0
-0
drivers/usb/host/xhci-debugfs.h struct xhci_file_map { · line 95
Quoted 5 lines
drivers/usb/host/xhci-debugfs.h +2
-0@@ -91,6 +91,11 @@ struct xhci_file_map {struct xhci_ep_priv {char name[DEBUGFS_NAMELEN ];struct dentry *root; +struct dentry *stream_ctx_dentry; +struct dentry *stream_id_dentry;
As I say above, are you sure you need to save these files?
thanks,
greg k-h
Quoted 168 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Thursday, July 16, 2020 12:06 AM
To: Jun Li <[email protected]>
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH] usb: xhci: add debugfs support for ep with streamQuoted 33 lines · Li Jun
To show the trb ring of streams, use the exsiting ring files of bulk ep to show trb ring of one specific stream ID, which stream ID's trb ring will be shown, is controlled by a new debugfs file
stream_id, this is to avoid to create a large number of dir for every allocate stream IDs, another debugfs filestream_context_arrayis created to show all the allocated stream context array entries.Signed-off-by Li Jun <[email protected]>--- drivers/usb/host/xhci-debugfs.c | 117 +++++++++++++++++++++++++++++++++++++++- drivers/usb/host/xhci-debugfs.h | 19 +++++++ drivers/usb/host/xhci-mem.c | 4 +- drivers/usb/host/xhci.c | 4 ++ 4 files changed, 142 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/usb/host/xhci-debugfs.cindex 65d8de4..0e17c4b 100644drivers/usb/host/xhci-debugfs.c +2
-1@@ -450,9 +450,10 @@ void xhci_debugfs_create_endpoint(struct xhci_hcd *xhci,if (!epriv)return ; + epriv->show_ring = dev->eps[ep_index].ring;snprintf (epriv->name,sizeof (epriv->name),"ep%02d" , ep_index); epriv->root =xhci_debugfs_create_ring_dir (xhci, - &dev->eps[ep_index].ring, + &epriv->show_ring, epriv->name, spriv->root); spriv->eps[ep_index] = epriv;drivers/usb/host/xhci-debugfs.c void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci, · line 481
Quoted 7 lines
drivers/usb/host/xhci-debugfs.c +4
-0@@ -474,6 +475,120 @@ void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci,kfree (epriv); } +static int xhci_stream_id_show (struct seq_file *s,void *unused) { +struct xhci_ep_priv *epriv = s->private; + + seq_printf(s, "Supported stream IDs are 1 ~ %d, trb ring to be shown is forstream id %d\n",
Quoted 78 lines
drivers/usb/host/xhci-debugfs.c +78
-0+ epriv->stream_info->num_streams - 1, epriv->stream_id); + +return 0 ; +} + +static int xhci_stream_id_open (struct inode *inode,struct file +*file) { +return single_open (file, xhci_stream_id_show, inode->i_private); } + +static ssize_t xhci_stream_id_write (struct file *file,const char __user *ubuf, +size_t count,loff_t *ppos) { +struct seq_file *s = file->private_data; +struct xhci_ep_priv *epriv = s->private; +int ret; +u16 stream_id;/* MaxPStreams + 1 <= 16 */ + +/* Decimal number */ + ret =kstrtou16_from_user (ubuf, count,10 , &stream_id); +if (ret) +return ret; + +if (stream_id ==0 || stream_id >= epriv->stream_info->num_streams) +return -EINVAL ; + + epriv->stream_id = stream_id; + epriv->show_ring = epriv->stream_info->stream_rings[stream_id]; + +return count; +} + +static const struct file_operations stream_id_fops = { + .open = xhci_stream_id_open, + .write = xhci_stream_id_write, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int xhci_stream_context_array_show (struct seq_file *s,void +*unused) { +struct xhci_ep_priv *epriv = s->private; +struct xhci_stream_ctx *stream_ctx; +dma_addr_t dma; +int id; + +seq_printf (s,"Allocated %d streams and %d stream context array entries\n" , + epriv->stream_info->num_streams, + epriv->stream_info->num_stream_ctxs); + +for (id =0 ; id < epriv->stream_info->num_stream_ctxs; id++) { + stream_ctx = epriv->stream_info->stream_ctx_array + id; + dma = epriv->stream_info->ctx_array_dma + id *16 ; +if (id < epriv->stream_info->num_streams) +seq_printf (s,"%pad stream id %d deq %016llx\n" , &dma, id, +le64_to_cpu (stream_ctx->stream_ring)); +else +seq_printf (s,"%pad stream context entry not used deq %016llx\n" , + &dma,le64_to_cpu (stream_ctx->stream_ring)); + } + +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (xhci_stream_context_array); + +void xhci_debugfs_create_stream_files (struct xhci_hcd *xhci, +struct xhci_virt_device *dev, +int ep_index) +{ +struct xhci_slot_priv *spriv = dev->debugfs_private; +struct xhci_ep_priv *epriv; + +if (!spriv || !spriv->eps[ep_index] || + !dev->eps[ep_index].stream_info) +return ; + + epriv = spriv->eps[ep_index]; + epriv->stream_info = dev->eps[ep_index].stream_info; +drivers/usb/host/xhci-debugfs.c void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci, · line 572
Quoted 10 lines
drivers/usb/host/xhci-debugfs.c +10
-0+/* Show trb ring of stream ID 1 by default */ + epriv->stream_id =1 ; + epriv->show_ring = epriv->stream_info->stream_rings[1 ]; + epriv->stream_ctx_dentry =debugfs_create_file ("stream_context_array" , +0444 , epriv->root, epriv, + &xhci_stream_context_array_fops); + + epriv->stream_id_dentry =debugfs_create_file ("stream_id" ,0644 , + epriv->root, epriv, + &stream_id_fops);Do you really need to save these files off, or could you use '
debug_remove_recursive()' to remove them all when the device goes away?Quoted 24 lines
drivers/usb/host/xhci-debugfs.c +19
-0+} + +void xhci_debugfs_remove_stream_files (struct xhci_hcd *xhci, +struct xhci_virt_device *dev, +int ep_index) +{ +struct xhci_slot_priv *spriv = dev->debugfs_private; +struct xhci_ep_priv *epriv; + +if (!spriv || !spriv->eps[ep_index] || + !dev->eps[ep_index].stream_info) +return ; + + epriv = spriv->eps[ep_index]; + epriv->show_ring = dev->eps[ep_index].ring; +debugfs_remove (epriv->stream_ctx_dentry); +debugfs_remove (epriv->stream_id_dentry); +} +void xhci_debugfs_create_slot (struct xhci_hcd *xhci,int slot_id) {struct xhci_slot_priv *priv;(quoted diff) +0
-0
b/drivers/usb/host/xhci-debugfs.hindex f7a4e24..d4d0af0 100644 ---a/drivers/usb/host/xhci-debugfs.h
Quoted 8 lines
drivers/usb/host/xhci-debugfs.h struct xhci_file_map { struct xhci_ep_priv { · line 94
Quoted 6 lines
+++
b/drivers/usb/host/xhci-debugfs.hdrivers/usb/host/xhci-debugfs.h +2
-0@@ -91,6 +91,11 @@ struct xhci_file_map { struct xhci_ep_priv {char name[DEBUGFS_NAMELEN ];struct dentry *root; +struct dentry *stream_ctx_dentry; +struct dentry *stream_id_dentry;As I say above, are you sure you need to save these files?
Actually no need after check, whole ep dir will be removed, I will remove these in v2.
Thanks
Li Jun
Quoted 4 lines
thanks,
greg k-h