All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] xhci fixes for usb-linus
@ 2021-05-12  8:08 Mathias Nyman
  2021-05-12  8:08 ` [PATCH 1/5] xhci-pci: Allow host runtime PM as default for Intel Alder Lake xHCI Mathias Nyman
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Mathias Nyman @ 2021-05-12  8:08 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Hi Greg

A few small xHCI fixes for usb-linus 5.13-rc.

Thanks
-Mathias


Abhijeet Rao (1):
  xhci-pci: Allow host runtime PM as default for Intel Alder Lake xHCI

Christophe JAILLET (1):
  xhci: Do not use GFP_KERNEL in (potentially) atomic context

Mathias Nyman (1):
  xhci: Fix giving back cancelled URBs even if halted endpoint can't
    reset

Maximilian Luz (1):
  usb: xhci: Increase timeout for HC halt

Sandeep Singh (1):
  xhci: Add reset resume quirk for AMD xhci controller.

 drivers/usb/host/xhci-ext-caps.h |  5 +++--
 drivers/usb/host/xhci-pci.c      |  8 ++++++--
 drivers/usb/host/xhci-ring.c     | 16 +++++++++++-----
 drivers/usb/host/xhci.c          |  6 +++---
 4 files changed, 23 insertions(+), 12 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] xhci-pci: Allow host runtime PM as default for Intel Alder Lake xHCI
  2021-05-12  8:08 [PATCH 0/5] xhci fixes for usb-linus Mathias Nyman
@ 2021-05-12  8:08 ` Mathias Nyman
  2021-05-12  8:08 ` [PATCH 2/5] xhci: Fix giving back cancelled URBs even if halted endpoint can't reset Mathias Nyman
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mathias Nyman @ 2021-05-12  8:08 UTC (permalink / raw)
  To: gregkh
  Cc: linux-usb, Abhijeet Rao, stable, Nikunj A . Dadhania,
	Azhar Shaikh, Mathias Nyman

From: Abhijeet Rao <abhijeet.rao@intel.com>

In the same way as Intel Tiger Lake TCSS (Type-C Subsystem) the Alder Lake
TCSS xHCI needs to be runtime suspended whenever possible to allow the
TCSS hardware block to enter D3cold and thus save energy.

Cc: stable@vger.kernel.org
Signed-off-by: Abhijeet Rao <abhijeet.rao@intel.com>
Signed-off-by: Nikunj A. Dadhania <nikunj.dadhania@intel.com>
Signed-off-by: Azhar Shaikh <azhar.shaikh@intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 5bbccc9a0179..a858add8436c 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -57,6 +57,7 @@
 #define PCI_DEVICE_ID_INTEL_CML_XHCI			0xa3af
 #define PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI		0x9a13
 #define PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI		0x1138
+#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_XHCI		0x461e
 
 #define PCI_DEVICE_ID_AMD_PROMONTORYA_4			0x43b9
 #define PCI_DEVICE_ID_AMD_PROMONTORYA_3			0x43ba
@@ -243,7 +244,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
 	     pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI ||
 	     pdev->device == PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI ||
 	     pdev->device == PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI ||
-	     pdev->device == PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI))
+	     pdev->device == PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI ||
+	     pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_XHCI))
 		xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
 
 	if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] xhci: Fix giving back cancelled URBs even if halted endpoint can't reset
  2021-05-12  8:08 [PATCH 0/5] xhci fixes for usb-linus Mathias Nyman
  2021-05-12  8:08 ` [PATCH 1/5] xhci-pci: Allow host runtime PM as default for Intel Alder Lake xHCI Mathias Nyman
@ 2021-05-12  8:08 ` Mathias Nyman
  2021-05-12  8:08 ` [PATCH 3/5] xhci: Do not use GFP_KERNEL in (potentially) atomic context Mathias Nyman
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mathias Nyman @ 2021-05-12  8:08 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman, stable

Commit 9ebf30007858 ("xhci: Fix halted endpoint at stop endpoint command
completion") in 5.12 changes how cancelled URBs are given back.

To cancel a URB xhci driver needs to stop the endpoint first.
To clear a halted endpoint xhci driver needs to reset the endpoint.

In rare cases when an endpoint halt (error) races with a endpoint stop we
need to clear the reset before removing, and giving back the cancelled URB.

The above change in 5.12 takes care of this, but it also relies on the
reset endpoint completion handler to give back the cancelled URBs.

There are cases when driver refuses to queue reset endpoint commands,
for example when a link suddenly goes to an inactive error state.
In this case the cancelled URB is never given back.

Fix this by giving back the URB in the stop endpoint if queuing a reset
endpoint command fails.

Fixes: 9ebf30007858 ("xhci: Fix halted endpoint at stop endpoint command completion")
CC: <stable@vger.kernel.org> # 5.12
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-ring.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 05c38dd3ee36..a8e4189277da 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -862,7 +862,7 @@ static int xhci_reset_halted_ep(struct xhci_hcd *xhci, unsigned int slot_id,
 	return ret;
 }
 
-static void xhci_handle_halted_endpoint(struct xhci_hcd *xhci,
+static int xhci_handle_halted_endpoint(struct xhci_hcd *xhci,
 				struct xhci_virt_ep *ep, unsigned int stream_id,
 				struct xhci_td *td,
 				enum xhci_ep_reset_type reset_type)
@@ -875,7 +875,7 @@ static void xhci_handle_halted_endpoint(struct xhci_hcd *xhci,
 	 * Device will be reset soon to recover the link so don't do anything
 	 */
 	if (ep->vdev->flags & VDEV_PORT_ERROR)
-		return;
+		return -ENODEV;
 
 	/* add td to cancelled list and let reset ep handler take care of it */
 	if (reset_type == EP_HARD_RESET) {
@@ -888,16 +888,18 @@ static void xhci_handle_halted_endpoint(struct xhci_hcd *xhci,
 
 	if (ep->ep_state & EP_HALTED) {
 		xhci_dbg(xhci, "Reset ep command already pending\n");
-		return;
+		return 0;
 	}
 
 	err = xhci_reset_halted_ep(xhci, slot_id, ep->ep_index, reset_type);
 	if (err)
-		return;
+		return err;
 
 	ep->ep_state |= EP_HALTED;
 
 	xhci_ring_cmd_db(xhci);
+
+	return 0;
 }
 
 /*
@@ -1014,6 +1016,7 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id,
 	struct xhci_td *td = NULL;
 	enum xhci_ep_reset_type reset_type;
 	struct xhci_command *command;
+	int err;
 
 	if (unlikely(TRB_TO_SUSPEND_PORT(le32_to_cpu(trb->generic.field[3])))) {
 		if (!xhci->devs[slot_id])
@@ -1058,7 +1061,10 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id,
 					td->status = -EPROTO;
 			}
 			/* reset ep, reset handler cleans up cancelled tds */
-			xhci_handle_halted_endpoint(xhci, ep, 0, td, reset_type);
+			err = xhci_handle_halted_endpoint(xhci, ep, 0, td,
+							  reset_type);
+			if (err)
+				break;
 			xhci_stop_watchdog_timer_in_irq(xhci, ep);
 			return;
 		case EP_STATE_RUNNING:
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] xhci: Do not use GFP_KERNEL in (potentially) atomic context
  2021-05-12  8:08 [PATCH 0/5] xhci fixes for usb-linus Mathias Nyman
  2021-05-12  8:08 ` [PATCH 1/5] xhci-pci: Allow host runtime PM as default for Intel Alder Lake xHCI Mathias Nyman
  2021-05-12  8:08 ` [PATCH 2/5] xhci: Fix giving back cancelled URBs even if halted endpoint can't reset Mathias Nyman
@ 2021-05-12  8:08 ` Mathias Nyman
  2021-05-12  8:08 ` [PATCH 4/5] usb: xhci: Increase timeout for HC halt Mathias Nyman
  2021-05-12  8:08 ` [PATCH 5/5] xhci: Add reset resume quirk for AMD xhci controller Mathias Nyman
  4 siblings, 0 replies; 6+ messages in thread
From: Mathias Nyman @ 2021-05-12  8:08 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Christophe JAILLET, stable, Mathias Nyman

From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

'xhci_urb_enqueue()' is passed a 'mem_flags' argument, because "URBs may be
submitted in interrupt context" (see comment related to 'usb_submit_urb()'
in 'drivers/usb/core/urb.c')

So this flag should be used in all the calling chain.
Up to now, 'xhci_check_maxpacket()' which is only called from
'xhci_urb_enqueue()', uses GFP_KERNEL.

Be safe and pass the mem_flags to this function as well.

Fixes: ddba5cd0aeff ("xhci: Use command structures when queuing commands on the command ring")
Cc: <stable@vger.kernel.org>
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index ca9385d22f68..27283654ca08 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1514,7 +1514,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
  * we need to issue an evaluate context command and wait on it.
  */
 static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id,
-		unsigned int ep_index, struct urb *urb)
+		unsigned int ep_index, struct urb *urb, gfp_t mem_flags)
 {
 	struct xhci_container_ctx *out_ctx;
 	struct xhci_input_control_ctx *ctrl_ctx;
@@ -1545,7 +1545,7 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id,
 		 * changes max packet sizes.
 		 */
 
-		command = xhci_alloc_command(xhci, true, GFP_KERNEL);
+		command = xhci_alloc_command(xhci, true, mem_flags);
 		if (!command)
 			return -ENOMEM;
 
@@ -1639,7 +1639,7 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
 		 */
 		if (urb->dev->speed == USB_SPEED_FULL) {
 			ret = xhci_check_maxpacket(xhci, slot_id,
-					ep_index, urb);
+					ep_index, urb, mem_flags);
 			if (ret < 0) {
 				xhci_urb_free_priv(urb_priv);
 				urb->hcpriv = NULL;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] usb: xhci: Increase timeout for HC halt
  2021-05-12  8:08 [PATCH 0/5] xhci fixes for usb-linus Mathias Nyman
                   ` (2 preceding siblings ...)
  2021-05-12  8:08 ` [PATCH 3/5] xhci: Do not use GFP_KERNEL in (potentially) atomic context Mathias Nyman
@ 2021-05-12  8:08 ` Mathias Nyman
  2021-05-12  8:08 ` [PATCH 5/5] xhci: Add reset resume quirk for AMD xhci controller Mathias Nyman
  4 siblings, 0 replies; 6+ messages in thread
From: Mathias Nyman @ 2021-05-12  8:08 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Maximilian Luz, stable, Mathias Nyman

From: Maximilian Luz <luzmaximilian@gmail.com>

On some devices (specifically the SC8180x based Surface Pro X with
QCOM04A6) HC halt / xhci_halt() times out during boot. Manually binding
the xhci-hcd driver at some point later does not exhibit this behavior.
To work around this, double XHCI_MAX_HALT_USEC, which also resolves this
issue.

Cc: <stable@vger.kernel.org>
Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-ext-caps.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-ext-caps.h b/drivers/usb/host/xhci-ext-caps.h
index fa59b242cd51..e8af0a125f84 100644
--- a/drivers/usb/host/xhci-ext-caps.h
+++ b/drivers/usb/host/xhci-ext-caps.h
@@ -7,8 +7,9 @@
  * Author: Sarah Sharp
  * Some code borrowed from the Linux EHCI driver.
  */
-/* Up to 16 ms to halt an HC */
-#define XHCI_MAX_HALT_USEC	(16*1000)
+
+/* HC should halt within 16 ms, but use 32 ms as some hosts take longer */
+#define XHCI_MAX_HALT_USEC	(32 * 1000)
 /* HC not running - set to 1 when run/stop bit is cleared. */
 #define XHCI_STS_HALT		(1<<0)
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] xhci: Add reset resume quirk for AMD xhci controller.
  2021-05-12  8:08 [PATCH 0/5] xhci fixes for usb-linus Mathias Nyman
                   ` (3 preceding siblings ...)
  2021-05-12  8:08 ` [PATCH 4/5] usb: xhci: Increase timeout for HC halt Mathias Nyman
@ 2021-05-12  8:08 ` Mathias Nyman
  4 siblings, 0 replies; 6+ messages in thread
From: Mathias Nyman @ 2021-05-12  8:08 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Sandeep Singh, stable, Mathias Nyman

From: Sandeep Singh <sandeep.singh@amd.com>

One of AMD xhci controller require reset on resume.
Occasionally AMD xhci controller does not respond to
Stop endpoint command.
Once the issue happens controller goes into bad state
and in that case controller needs to be reset.

Cc: <stable@vger.kernel.org>
Signed-off-by: Sandeep Singh <sandeep.singh@amd.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index a858add8436c..7bc18cf8042c 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -167,8 +167,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
 	    (pdev->device == 0x15e0 || pdev->device == 0x15e1))
 		xhci->quirks |= XHCI_SNPS_BROKEN_SUSPEND;
 
-	if (pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x15e5)
+	if (pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x15e5) {
 		xhci->quirks |= XHCI_DISABLE_SPARSE;
+		xhci->quirks |= XHCI_RESET_ON_RESUME;
+	}
 
 	if (pdev->vendor == PCI_VENDOR_ID_AMD)
 		xhci->quirks |= XHCI_TRUST_TX_LENGTH;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-12  8:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12  8:08 [PATCH 0/5] xhci fixes for usb-linus Mathias Nyman
2021-05-12  8:08 ` [PATCH 1/5] xhci-pci: Allow host runtime PM as default for Intel Alder Lake xHCI Mathias Nyman
2021-05-12  8:08 ` [PATCH 2/5] xhci: Fix giving back cancelled URBs even if halted endpoint can't reset Mathias Nyman
2021-05-12  8:08 ` [PATCH 3/5] xhci: Do not use GFP_KERNEL in (potentially) atomic context Mathias Nyman
2021-05-12  8:08 ` [PATCH 4/5] usb: xhci: Increase timeout for HC halt Mathias Nyman
2021-05-12  8:08 ` [PATCH 5/5] xhci: Add reset resume quirk for AMD xhci controller Mathias Nyman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.