xhci features for usb-next
Subsystems (3)
cover xhci features for usb-next
Hi Greg
A few minor xhci improvements for usb-next
-Mathias
Li Jun (1):
usb: xhci: add debugfs support for ep with stream
Mathias Nyman (2):
xhci: Tune interrupt blocking for isochronous transfers
xhci: don't create endpoint debugfs entry before ring buffer is set.
Peter Chen (7):
usb: host: xhci-plat: add platform data support
usb: host: xhci-plat: add .suspend_quirk for struct xhci_plat_priv
usb: host: xhci-plat: delete the unnecessary code
usb: host: xhci-plat: add priv quirk for skip PHY initialization
usb: host: xhci-plat: add wakeup entry at sysfs
usb: host: xhci-plat: improve the comments for xhci_plat_suspend
usb: xhci: omit duplicate actions when suspending a runtime suspended
host.
drivers/usb/host/xhci-debugfs.c | 109 +++++++++++++++++++++++++++++++- drivers/usb/host/xhci-debugfs.h | 10 +++ drivers/usb/host/xhci-plat.c | 44 +++++++++---- drivers/usb/host/xhci-plat.h | 1 + drivers/usb/host/xhci-ring.c | 23 +++++-- drivers/usb/host/xhci.c | 11 ++-- drivers/usb/host/xhci.h | 1 + 7 files changed, 179 insertions(+), 20 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/10 usb: host: xhci-plat: add platform data support
From: Peter Chen <[email protected]>
Some xhci hosts (eg dwc3 and cdns3) do not use OF to create platform device, they create xhci-plat platform device runtime. And these platforms may also have quirks, and the quirks could be supplied by their parent device through platform data.
--- drivers/usb/host/xhci-plat.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-plat.c +5 -1
@@ -264,7 +264,11 @@ static int xhci_plat_probe(struct platform_device *pdev)if (ret) goto disable_reg_clk; - priv_match =of_device_get_match_data (&pdev->dev); +if (pdev->dev.of_node) + priv_match =of_device_get_match_data (&pdev->dev); +else + priv_match =dev_get_platdata (&pdev->dev); +if (priv_match) {struct xhci_plat_priv *priv =hcd_to_xhci_priv (hcd);
Signature · 1 line
2.17.1
PATCH 2/10 usb: host: xhci-plat: add .suspend_quirk for struct xhci_plat_priv
In reply to Mathias NymanFrom: Peter Chen <[email protected]>
Some platforms (eg cdns3) may have special sequences between xhci_bus_suspend and xhci_suspend, add .suspend_quick for it.
--- drivers/usb/host/xhci-plat.c | 19 +++++++++++++++++++ drivers/usb/host/xhci-plat.h | 1 + 2 files changed, 20 insertions(+)
drivers/usb/host/xhci-plat.c +19 -0
@@ -54,6 +54,16 @@ static int xhci_priv_init_quirk(struct usb_hcd *hcd)return priv->init_quirk (hcd); } +static int xhci_priv_suspend_quirk (struct usb_hcd *hcd) +{ +struct xhci_plat_priv *priv =hcd_to_xhci_priv (hcd); + +if (!priv->suspend_quirk) +return 0 ; + +return priv->suspend_quirk (hcd); +} +static int xhci_priv_resume_quirk (struct usb_hcd *hcd) {struct xhci_plat_priv *priv =hcd_to_xhci_priv (hcd);
@@ -401,7 +411,11 @@ static int __maybe_unused xhci_plat_suspend(struct device *dev) {struct usb_hcd *hcd =dev_get_drvdata (dev);struct xhci_hcd *xhci =hcd_to_xhci (hcd); +int ret; + ret =xhci_priv_suspend_quirk (hcd); +if (ret) +return ret;/* * xhci_suspend() needs `do_wakeup` to know whether host is allowed * to do wakeup during suspend. Since xhci_plat_suspend is currently
@@ -438,6 +452,11 @@ static int __maybe_unused xhci_plat_runtime_suspend(struct device *dev) {struct usb_hcd *hcd =dev_get_drvdata (dev);struct xhci_hcd *xhci =hcd_to_xhci (hcd); +int ret; + + ret =xhci_priv_suspend_quirk (hcd); +if (ret) +return ret;return xhci_suspend (xhci, true); }
drivers/usb/host/xhci-plat.h +1 -0
@@ -15,6 +15,7 @@ struct xhci_plat_priv {unsigned long long quirks;void (*plat_start)(struct usb_hcd *);int (*init_quirk)(struct usb_hcd *); +int (*suspend_quirk)(struct usb_hcd *);int (*resume_quirk)(struct usb_hcd *); };
Signature · 1 line
2.17.1
PATCH 3/10 usb: host: xhci-plat: delete the unnecessary code
In reply to Mathias NymanFrom: Peter Chen <[email protected]>
The if {} condition is duplicated with outer if {} condition.
--- drivers/usb/host/xhci-plat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/host/xhci-plat.c +1 -2
@@ -283,8 +283,7 @@ static int xhci_plat_probe(struct platform_device *pdev)struct xhci_plat_priv *priv =hcd_to_xhci_priv (hcd);/* Just copy data for now */ -if (priv_match) - *priv = *priv_match; + *priv = *priv_match; }device_wakeup_enable (hcd->self.controller);
Signature · 1 line
2.17.1
PATCH 4/10 usb: host: xhci-plat: add priv quirk for skip PHY initialization
In reply to Mathias NymanFrom: Peter Chen <[email protected]>
Some DRD controllers (eg, dwc3 & cdns3) have PHY management at their own driver to cover both device and host mode, so add one priv quirk for such users to skip PHY management from HCD core.
--- drivers/usb/host/xhci-plat.c | 8 ++++++-- drivers/usb/host/xhci.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-plat.c +6 -2
@@ -183,6 +183,8 @@ static int xhci_plat_probe(struct platform_device *pdev)struct usb_hcd *hcd;int ret;int irq; +struct xhci_plat_priv *priv =NULL ; +if (usb_disabled ())return -ENODEV ;
@@ -280,8 +282,7 @@ static int xhci_plat_probe(struct platform_device *pdev) priv_match =dev_get_platdata (&pdev->dev);if (priv_match) { -struct xhci_plat_priv *priv =hcd_to_xhci_priv (hcd); - + priv =hcd_to_xhci_priv (hcd);/* Just copy data for now */ *priv = *priv_match; }
@@ -329,6 +330,9 @@ static int xhci_plat_probe(struct platform_device *pdev) hcd->tpl_support =of_usb_host_tpl_support (sysdev->of_node); xhci->shared_hcd->tpl_support = hcd->tpl_support; +if (priv && (priv->quirks &XHCI_SKIP_PHY_INIT )) + hcd->skip_phy_initialization =1 ; + ret =usb_add_hcd (hcd, irq,IRQF_SHARED );if (ret) goto disable_usb_phy;
drivers/usb/host/xhci.h +1 -0
@@ -1874,6 +1874,7 @@ struct xhci_hcd {#define XHCI_RESET_PLL_ON_DISCONNECT BIT_ULL(34)#define XHCI_SNPS_BROKEN_SUSPEND BIT_ULL(35)#define XHCI_RENESAS_FW_QUIRK BIT_ULL(36) +#define XHCI_SKIP_PHY_INIT BIT_ULL(37)unsigned int num_active_eps;unsigned int limit_active_eps;
Signature · 1 line
2.17.1
PATCH 5/10 usb: host: xhci-plat: add wakeup entry at sysfs
In reply to Mathias NymanFrom: Peter Chen <[email protected]>
With this change, there will be a wakeup entry at /sys/../power/wakeup, and the user could use this entry to choose whether enable xhci wakeup features (wake up system from suspend) or not.
--- drivers/usb/host/xhci-plat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-plat.c +1 -1
@@ -287,7 +287,7 @@ static int xhci_plat_probe(struct platform_device *pdev) *priv = *priv_match; } -device_wakeup_enable (hcd->self.controller); +device_set_wakeup_capable (&pdev->dev, true); xhci->main_hcd = hcd; xhci->shared_hcd = __usb_create_hcd(driver, sysdev, &pdev->dev,
Signature · 1 line
2.17.1
PATCH 6/10 usb: host: xhci-plat: improve the comments for xhci_plat_suspend
In reply to Mathias NymanFrom: Peter Chen <[email protected]>
To reflect the current code status.
--- drivers/usb/host/xhci-plat.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/usb/host/xhci-plat.c +1 -5
@@ -421,11 +421,7 @@ static int __maybe_unused xhci_plat_suspend(struct device *dev)return ret;/* * xhci_suspend() needs `do_wakeup` to know whether host is allowed -* to do wakeup during suspend. Since xhci_plat_suspend is currently -* only designed for system suspend, device_may_wakeup() is enough -* to dertermine whether host is allowed to do wakeup. Need to -* reconsider this when xhci_plat_suspend enlarges its scope, e.g., -* also applies to runtime suspend. +* to do wakeup during suspend. */ return xhci_suspend (xhci,device_may_wakeup (dev)); }
Signature · 1 line
2.17.1
PATCH 7/10 usb: xhci: omit duplicate actions when suspending a runtime suspended host.
In reply to Mathias NymanFrom: Peter Chen <[email protected]>
If the xhci-plat.c is the platform driver, after the runtime pm is enabled, the xhci_suspend is called if nothing is connected on the port. When the system goes to suspend, it will call xhci_suspend again if USB wakeup is enabled.
Since the runtime suspend wakeup setting is not always the same as system suspend wakeup setting, eg, at runtime suspend we always need wakeup if the controller is in low power mode; but at system suspend, we may not need wakeup. So, we move the judgement after changing wakeup setting.
--- drivers/usb/host/xhci.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/host/xhci.c +5 -2
@@ -982,12 +982,15 @@ int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup) xhci->shared_hcd->state != HC_STATE_SUSPENDED)return -EINVAL ; -xhci_dbc_suspend (xhci); -/* Clear root port wake on bits if wakeup not allowed. */ if (!do_wakeup)xhci_disable_port_wake_on_bits (xhci); +if (!HCD_HW_ACCESSIBLE (hcd)) +return 0 ; + +xhci_dbc_suspend (xhci); +/* Don't poll the roothubs on bus suspend. */ xhci_dbg (xhci,"%s: stopping port polling.\n" , __func__);clear_bit (HCD_FLAG_POLL_RH , &hcd->flags);
Signature · 1 line
2.17.1
PATCH 8/10 xhci: Tune interrupt blocking for isochronous transfers
In reply to Mathias Nymancontrollers with XHCI_AVOID_BEI quirk cause too frequent interrupts and affect power management.
To avoid interrupting on every isochronous interval the BEI (Block Event Interrupt) flag is set for all except the last Isoch TRB in a URB. This lead to event ring filling up in case several isoc URB were queued and cancelled rapidly, which some controllers didn't handle well, and thus the XHCI_AVOID_BEI quirk was introduced. see commit 227a4fd801c8 ("usb: xhci: apply XHCI_AVOID_BEI quirk to all Intel xHCI controllers")
With the XHCI_AVOID_BEI quirk each Isoch TRB will trigger an interrupt. This can cause up to 8000 interrupts per second for isochronous transfers with HD USB3 cameras, affecting power saving.
The event ring fits 256 events, instead of interrupting on every isochronous TRB if XHCI_AVOID_BEI is set we make sure at least every 8th Isochronous TRB asserts an interrupt, clearing the event ring.
--- drivers/usb/host/xhci-ring.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/usb/host/xhci-ring.c +19 -4
@@ -3736,6 +3736,24 @@ static int xhci_get_isoc_frame_id(struct xhci_hcd *xhci,return start_frame; } +/* Check if we should generate event interrupt for a TD in an isoc URB */ +static bool trb_block_event_intr (struct xhci_hcd *xhci,int num_tds,int i) +{ +if (xhci->hci_version <0x100 ) +return false; +/* always generate an event interrupt for the last TD */ +if (i == num_tds -1 ) +return false; +/* +* If AVOID_BEI is set the host handles full event rings poorly, +* generate an event at least every 8th TD to clear the event ring +*/ +if (i && xhci->quirks &XHCI_AVOID_BEI ) +return !!(i %8 ); + +return true; +} +/* This is for isoc transfer */ static int xhci_queue_isoc_tx (struct xhci_hcd *xhci,gfp_t mem_flags,struct urb *urb,int slot_id,unsigned int ep_index)
@@ -3843,10 +3861,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, more_trbs_coming = false; td->last_trb = ep_ring->enqueue; field |=TRB_IOC ; -/* set BEI, except for the last TD */ -if (xhci->hci_version >=0x100 && - !(xhci->quirks &XHCI_AVOID_BEI ) && - i < num_tds -1 ) +if (trb_block_event_intr (xhci, num_tds, i)) field |=TRB_BEI ; }/* Calculate TRB length */
Signature · 1 line
2.17.1
PATCH 9/10 xhci: don't create endpoint debugfs entry before ring buffer is set.
In reply to Mathias NymanMake sure xHC completes the configure endpoint command and xhci driver sets the ring pointers correctly before we create the user readable debugfs file.
In theory there was a small gap where a user could have read the debugfs file and cause a NULL pointer dereference error as ring pointer was not yet set, in practise we want this change to simplify the upcoming streams debugfs support.
--- drivers/usb/host/xhci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/host/xhci.c +1 -2
@@ -1918,8 +1918,6 @@ static int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, ep_ctx =xhci_get_ep_ctx (xhci, virt_dev->in_ctx, ep_index);trace_xhci_add_endpoint (ep_ctx); -xhci_debugfs_create_endpoint (xhci, virt_dev, ep_index); - xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", (unsigned int) ep->desc.bEndpointAddress, udev->slot_id,
@@ -2952,6 +2950,7 @@ static int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)xhci_check_bw_drop_ep_streams (xhci, virt_dev, i); virt_dev->eps[i].ring = virt_dev->eps[i].new_ring; virt_dev->eps[i].new_ring =NULL ; +xhci_debugfs_create_endpoint (xhci, virt_dev, i); } command_cleanup:kfree (command->completion);
Signature · 1 line
2.17.1
Sasha Levin
maintainerRe: [PATCH 09/10] xhci: don't create endpoint debugfs entry before ring buffer is set.
Hi
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag fixing commit: 02b6fdc2a153 ("usb: xhci: Add debugfs interface for xHCI driver").
The bot has tested the following trees: v5.8.10, v5.4.66, v4.19.146.
v5.8.10: Build OK!
v5.4.66: Build OK!
v4.19.146: Failed to apply! Possible dependencies:
5afa0a5ed3da ("usb: xhci: add endpoint context tracing when an endpoint is added")
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
Signature · 2 lines
Thanks Sasha
PATCH 10/10 usb: xhci: add debugfs support for ep with stream
In reply to Mathias NymanFrom: Li Jun <[email protected]>
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 | 109 +++++++++++++++++++++++++++++++- drivers/usb/host/xhci-debugfs.h | 10 +++ drivers/usb/host/xhci.c | 1 + 3 files changed, 119 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-debugfs.c +108 -1
@@ -451,9 +451,11 @@ 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;
@@ -475,6 +477,111 @@ 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; + +if (!epriv->stream_info) +return -EPERM ; + +seq_printf (s,"Show stream ID %d trb ring, supported [1 - %d]\n" , + epriv->stream_id, epriv->stream_info->num_streams -1 ); + +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 */ + +if (!epriv->stream_info) +return -EPERM ; + +/* 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; + +if (!epriv->stream_info) +return -EPERM ; + +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 ]; +debugfs_create_file ("stream_id" ,0644 , + epriv->root, epriv, + &stream_id_fops); +debugfs_create_file ("stream_context_array" ,0444 , + epriv->root, epriv, + &xhci_stream_context_array_fops); +} +void xhci_debugfs_create_slot (struct xhci_hcd *xhci,int slot_id) {struct xhci_slot_priv *priv;
drivers/usb/host/xhci-debugfs.h +10 -0
@@ -91,6 +91,9 @@ struct xhci_file_map {struct xhci_ep_priv {char name[DEBUGFS_NAMELEN ];struct dentry *root; +struct xhci_stream_info *stream_info; +struct xhci_ring *show_ring; +unsigned int stream_id; };struct xhci_slot_priv {
@@ -113,6 +116,9 @@ 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);#else static inline void xhci_debugfs_init (struct xhci_hcd *xhci) { }static inline void xhci_debugfs_exit (struct xhci_hcd *xhci) { }
@@ -128,6 +134,10 @@ 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_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.c +1 -0
@@ -3533,6 +3533,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);
Signature · 1 line
2.17.1