linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/4] Fix some issues of xHCI for zhaoxin
@ 2023-05-06 20:15 Weitao Wang
  2023-05-06 20:15 ` [PATCH v3 1/4] xhci: Add some quirks for zhaoxin xhci to fix issues Weitao Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Weitao Wang @ 2023-05-06 20:15 UTC (permalink / raw)
  To: gregkh, mathias.nyman, linux-usb, linux-kernel; +Cc: tonywwang, weitaowang

Fix some issues of xHCI for zhaoxin.

Weitao Wang (4):
  xhci: Add some quirks for zhaoxin xhci to fix issues
  xhci: fix issue of cross page boundary in TRB prefetch
  xhci: Show zhaoxin xHCI root hub speed correctly
  xhci: Add zhaoxin xHCI U1/U2 feature support

 drivers/usb/host/xhci-mem.c | 38 ++++++++++++++++++++++++--------
 drivers/usb/host/xhci-pci.c | 12 +++++++++++
 drivers/usb/host/xhci.c     | 43 ++++++++++++++++---------------------
 drivers/usb/host/xhci.h     |  2 ++
 4 files changed, 61 insertions(+), 34 deletions(-)

-- 
2.32.0


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

* [PATCH v3 1/4] xhci: Add some quirks for zhaoxin xhci to fix issues
  2023-05-06 20:15 [PATCH v3 0/4] Fix some issues of xHCI for zhaoxin Weitao Wang
@ 2023-05-06 20:15 ` Weitao Wang
  2023-05-08  9:01   ` Mathias Nyman
  2023-05-06 20:15 ` [PATCH v3 2/4] xhci: fix issue of cross page boundary in TRB prefetch Weitao Wang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Weitao Wang @ 2023-05-06 20:15 UTC (permalink / raw)
  To: gregkh, mathias.nyman, linux-usb, linux-kernel
  Cc: tonywwang, weitaowang, stable

Add a quirk XHCI_ZHAOXIN_HOST for zhaoxin xhci to fix issues,
there are two cases will be used.
- add u1/u2 support.
- fix xHCI root hub speed show issue in zhaoxin platform.

Add a quirk XHCI_ZHAOXIN_TRB_FETCH to fix TRB prefetch issue.

On Zhaoxin ZX-100 project, xHCI can't work normally after resume
from system Sx state. To fix this issue, when resume from system
Sx state, reinitialize xHCI instead of restore.
So, Add XHCI_RESET_ON_RESUME quirk for ZX-100 to fix issue of
resuming from system Sx state.

Cc: stable@vger.kernel.org
Signed-off-by: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
---
 drivers/usb/host/xhci-pci.c | 12 ++++++++++++
 drivers/usb/host/xhci.h     |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index ddb79f23fb3b..3fd73fceb678 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -527,6 +527,18 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
 	     pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4))
 		xhci->quirks |= XHCI_NO_SOFT_RETRY;
 
+	if (pdev->vendor == PCI_VENDOR_ID_ZHAOXIN) {
+		xhci->quirks |= XHCI_LPM_SUPPORT;
+		xhci->quirks |= XHCI_ZHAOXIN_HOST;
+
+		if (pdev->device == 0x9202) {
+			xhci->quirks |= XHCI_RESET_ON_RESUME;
+			xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH;
+		}
+		if (pdev->device == 0x9203)
+			xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH;
+	}
+
 	/* xHC spec requires PCI devices to support D3hot and D3cold */
 	if (xhci->hci_version >= 0x120)
 		xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 08d721921b7b..5fe1238eeb2d 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1905,6 +1905,8 @@ struct xhci_hcd {
 #define XHCI_EP_CTX_BROKEN_DCS	BIT_ULL(42)
 #define XHCI_SUSPEND_RESUME_CLKS	BIT_ULL(43)
 #define XHCI_RESET_TO_DEFAULT	BIT_ULL(44)
+#define XHCI_ZHAOXIN_HOST	BIT_ULL(45)
+#define XHCI_ZHAOXIN_TRB_FETCH	BIT_ULL(46)
 
 	unsigned int		num_active_eps;
 	unsigned int		limit_active_eps;
-- 
2.32.0


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

* [PATCH v3 2/4] xhci: fix issue of cross page boundary in TRB prefetch
  2023-05-06 20:15 [PATCH v3 0/4] Fix some issues of xHCI for zhaoxin Weitao Wang
  2023-05-06 20:15 ` [PATCH v3 1/4] xhci: Add some quirks for zhaoxin xhci to fix issues Weitao Wang
@ 2023-05-06 20:15 ` Weitao Wang
  2023-05-06 20:15 ` [PATCH v3 3/4] xhci: Show zhaoxin xHCI root hub speed correctly Weitao Wang
  2023-05-06 20:15 ` [PATCH v3 4/4] xhci: Add zhaoxin xHCI U1/U2 feature support Weitao Wang
  3 siblings, 0 replies; 7+ messages in thread
From: Weitao Wang @ 2023-05-06 20:15 UTC (permalink / raw)
  To: gregkh, mathias.nyman, linux-usb, linux-kernel
  Cc: tonywwang, weitaowang, stable

On some Zhaoxin platforms, xHCI will prefetch TRB for performance
improvement. However this TRB prefetch mechanism may cross page boundary,
which may access memory not allocated by xHCI driver. In order to fix
this issue, two pages was allocated for TRB and only the first
page will be used.

Cc: stable@vger.kernel.org
Signed-off-by: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
---
 drivers/usb/host/xhci-mem.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 7e106bd804ca..6d00980d0070 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2352,8 +2352,12 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	 * and our use of dma addresses in the trb_address_map radix tree needs
 	 * TRB_SEGMENT_SIZE alignment, so we pick the greater alignment need.
 	 */
-	xhci->segment_pool = dma_pool_create("xHCI ring segments", dev,
-			TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size);
+	if (xhci->quirks & XHCI_ZHAOXIN_TRB_FETCH)
+		xhci->segment_pool = dma_pool_create("xHCI ring segments", dev,
+				TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size);
+	else
+		xhci->segment_pool = dma_pool_create("xHCI ring segments", dev,
+				TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size);
 
 	/* See Table 46 and Note on Figure 55 */
 	xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev,
-- 
2.32.0


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

* [PATCH v3 3/4] xhci: Show zhaoxin xHCI root hub speed correctly
  2023-05-06 20:15 [PATCH v3 0/4] Fix some issues of xHCI for zhaoxin Weitao Wang
  2023-05-06 20:15 ` [PATCH v3 1/4] xhci: Add some quirks for zhaoxin xhci to fix issues Weitao Wang
  2023-05-06 20:15 ` [PATCH v3 2/4] xhci: fix issue of cross page boundary in TRB prefetch Weitao Wang
@ 2023-05-06 20:15 ` Weitao Wang
  2023-05-06 20:15 ` [PATCH v3 4/4] xhci: Add zhaoxin xHCI U1/U2 feature support Weitao Wang
  3 siblings, 0 replies; 7+ messages in thread
From: Weitao Wang @ 2023-05-06 20:15 UTC (permalink / raw)
  To: gregkh, mathias.nyman, linux-usb, linux-kernel
  Cc: tonywwang, weitaowang, Mathias Nyman

Some zhaoxin xHCI controllers follow usb3.1 spec,
but only support gen1 speed 5Gbps. While in Linux kernel,
if xHCI suspport usb3.1, root hub speed will show on 10Gbps.
To fix this issue of zhaoxin xHCI platforms, read usb speed ID
supported by xHCI to determine root hub speed.

Suggested-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
---
v2->v3
 - Checking port whether support over 5Gbps when parse the protocol
 speed id in xhci_add_in_port_function.

 drivers/usb/host/xhci-mem.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 6d00980d0070..8b36ff0f3e69 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1968,7 +1968,7 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
 {
 	u32 temp, port_offset, port_count;
 	int i;
-	u8 major_revision, minor_revision;
+	u8 major_revision, minor_revision, tmp_minor_revision;
 	struct xhci_hub *rhub;
 	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 	struct xhci_port_cap *port_cap;
@@ -1988,6 +1988,15 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
 		 */
 		if (minor_revision > 0x00 && minor_revision < 0x10)
 			minor_revision <<= 4;
+		/*
+		 * Some zhaoxin's xHCI controller that follow usb3.1 spec
+		 * but only support gen1.
+		 */
+		if (xhci->quirks & XHCI_ZHAOXIN_HOST) {
+			tmp_minor_revision = minor_revision;
+			minor_revision = 0;
+		}
+
 	} else if (major_revision <= 0x02) {
 		rhub = &xhci->usb2_rhub;
 	} else {
@@ -1996,10 +2005,6 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
 		/* Ignoring port protocol we can't understand. FIXME */
 		return;
 	}
-	rhub->maj_rev = XHCI_EXT_PORT_MAJOR(temp);
-
-	if (rhub->min_rev < minor_revision)
-		rhub->min_rev = minor_revision;
 
 	/* Port offset and count in the third dword, see section 7.2 */
 	temp = readl(addr + 2);
@@ -2017,8 +2022,6 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
 	if (xhci->num_port_caps > max_caps)
 		return;
 
-	port_cap->maj_rev = major_revision;
-	port_cap->min_rev = minor_revision;
 	port_cap->psi_count = XHCI_EXT_PORT_PSIC(temp);
 
 	if (port_cap->psi_count) {
@@ -2039,6 +2042,10 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
 				  XHCI_EXT_PORT_PSIV(port_cap->psi[i - 1])))
 				port_cap->psi_uid_count++;
 
+			if (xhci->quirks & XHCI_ZHAOXIN_HOST &&
+					XHCI_EXT_PORT_PSIV(port_cap->psi[i]) >= 5)
+				minor_revision = tmp_minor_revision;
+
 			xhci_dbg(xhci, "PSIV:%d PSIE:%d PLT:%d PFD:%d LP:%d PSIM:%d\n",
 				  XHCI_EXT_PORT_PSIV(port_cap->psi[i]),
 				  XHCI_EXT_PORT_PSIE(port_cap->psi[i]),
@@ -2048,6 +2055,15 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
 				  XHCI_EXT_PORT_PSIM(port_cap->psi[i]));
 		}
 	}
+
+	rhub->maj_rev = major_revision;
+
+	if (rhub->min_rev < minor_revision)
+		rhub->min_rev = minor_revision;
+
+	port_cap->maj_rev = major_revision;
+	port_cap->min_rev = minor_revision;
+
 	/* cache usb2 port capabilities */
 	if (major_revision < 0x03 && xhci->num_ext_caps < max_caps)
 		xhci->ext_caps[xhci->num_ext_caps++] = temp;
-- 
2.32.0


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

* [PATCH v3 4/4] xhci: Add zhaoxin xHCI U1/U2 feature support
  2023-05-06 20:15 [PATCH v3 0/4] Fix some issues of xHCI for zhaoxin Weitao Wang
                   ` (2 preceding siblings ...)
  2023-05-06 20:15 ` [PATCH v3 3/4] xhci: Show zhaoxin xHCI root hub speed correctly Weitao Wang
@ 2023-05-06 20:15 ` Weitao Wang
  3 siblings, 0 replies; 7+ messages in thread
From: Weitao Wang @ 2023-05-06 20:15 UTC (permalink / raw)
  To: gregkh, mathias.nyman, linux-usb, linux-kernel
  Cc: tonywwang, weitaowang, Mathias Nyman, stable

Add U1/U2 feature support of xHCI for zhaoxin.

Since both Intel and Zhaoxin need to check the tier where the device is
located to determine whether to enabled U1/U2, remove the previous Intel
U1/U2 tier policy and add common policy in xhci_check_tier_policy.
If vendor has specific U1/U2 enable policy,quirks can be add to declare.

Suggested-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Cc: stable@vger.kernel.org
Signed-off-by: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
---
 drivers/usb/host/xhci.c | 43 +++++++++++++++++------------------------
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 78790dc13c5f..cae57f0207a4 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4604,7 +4604,7 @@ static u16 xhci_calculate_u1_timeout(struct xhci_hcd *xhci,
 		}
 	}
 
-	if (xhci->quirks & XHCI_INTEL_HOST)
+	if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST))
 		timeout_ns = xhci_calculate_intel_u1_timeout(udev, desc);
 	else
 		timeout_ns = udev->u1_params.sel;
@@ -4668,7 +4668,7 @@ static u16 xhci_calculate_u2_timeout(struct xhci_hcd *xhci,
 		}
 	}
 
-	if (xhci->quirks & XHCI_INTEL_HOST)
+	if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST))
 		timeout_ns = xhci_calculate_intel_u2_timeout(udev, desc);
 	else
 		timeout_ns = udev->u2_params.sel;
@@ -4740,37 +4740,30 @@ static int xhci_update_timeout_for_interface(struct xhci_hcd *xhci,
 	return 0;
 }
 
-static int xhci_check_intel_tier_policy(struct usb_device *udev,
+static int xhci_check_tier_policy(struct xhci_hcd *xhci,
+		struct usb_device *udev,
 		enum usb3_link_state state)
 {
-	struct usb_device *parent;
-	unsigned int num_hubs;
+	struct usb_device *parent = udev->parent;
+	int tier = 1; /* roothub is tier1 */
 
-	/* Don't enable U1 if the device is on a 2nd tier hub or lower. */
-	for (parent = udev->parent, num_hubs = 0; parent->parent;
-			parent = parent->parent)
-		num_hubs++;
+	while (parent) {
+		parent = parent->parent;
+		tier++;
+	}
 
-	if (num_hubs < 2)
-		return 0;
+	if (xhci->quirks & XHCI_INTEL_HOST && tier > 3)
+		goto fail;
+	if (xhci->quirks & XHCI_ZHAOXIN_HOST && tier > 2)
+		goto fail;
 
-	dev_dbg(&udev->dev, "Disabling U1/U2 link state for device"
-			" below second-tier hub.\n");
-	dev_dbg(&udev->dev, "Plug device into first-tier hub "
-			"to decrease power consumption.\n");
+	return 0;
+fail:
+	dev_dbg(&udev->dev, "Tier policy prevents U1/U2 LPM states for devices at tier %d\n",
+			tier);
 	return -E2BIG;
 }
 
-static int xhci_check_tier_policy(struct xhci_hcd *xhci,
-		struct usb_device *udev,
-		enum usb3_link_state state)
-{
-	if (xhci->quirks & XHCI_INTEL_HOST)
-		return xhci_check_intel_tier_policy(udev, state);
-	else
-		return 0;
-}
-
 /* Returns the U1 or U2 timeout that should be enabled.
  * If the tier check or timeout setting functions return with a non-zero exit
  * code, that means the timeout value has been finalized and we shouldn't look
-- 
2.32.0


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

* Re: [PATCH v3 1/4] xhci: Add some quirks for zhaoxin xhci to fix issues
  2023-05-06 20:15 ` [PATCH v3 1/4] xhci: Add some quirks for zhaoxin xhci to fix issues Weitao Wang
@ 2023-05-08  9:01   ` Mathias Nyman
  2023-05-08 17:33     ` WeitaoWang-oc
  0 siblings, 1 reply; 7+ messages in thread
From: Mathias Nyman @ 2023-05-08  9:01 UTC (permalink / raw)
  To: Weitao Wang, gregkh, mathias.nyman, linux-usb, linux-kernel
  Cc: tonywwang, weitaowang, stable

On 6.5.2023 23.15, Weitao Wang wrote:
> Add a quirk XHCI_ZHAOXIN_HOST for zhaoxin xhci to fix issues,
> there are two cases will be used.
> - add u1/u2 support.
> - fix xHCI root hub speed show issue in zhaoxin platform.
> 
> Add a quirk XHCI_ZHAOXIN_TRB_FETCH to fix TRB prefetch issue.
> 
> On Zhaoxin ZX-100 project, xHCI can't work normally after resume
> from system Sx state. To fix this issue, when resume from system
> Sx state, reinitialize xHCI instead of restore.
> So, Add XHCI_RESET_ON_RESUME quirk for ZX-100 to fix issue of
> resuming from system Sx state.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Weitao Wang <WeitaoWang-oc@zhaoxin.com>


I'd split this series into different logical parts:

patch 1/4
   Set XHCI_RESET_ON_RESUME quirk to ZHAOXIN host to fix resume issue.
   cc: stable

patch 2/4
   Add XHCI_ZHAOXIN_TRB_FETCH quirk flag together with code that allocates double pages
   cc: stable

patch 3/4
   Add XHCI_ZHAOXIN_HOST quirk flag together with code that corrects USB3 roothub minor version
   cc: stable

patch 4/4
   Set XHCI_LPM_SUPPORT quirk together with code that sets tier policy and u1/u2 timeouts,
   Don't add stable as this is about adding feature support.

(Accidentally replied to older v2 series with the above comments)

Thanks
-Mathias


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

* Re: [PATCH v3 1/4] xhci: Add some quirks for zhaoxin xhci to fix issues
  2023-05-08  9:01   ` Mathias Nyman
@ 2023-05-08 17:33     ` WeitaoWang-oc
  0 siblings, 0 replies; 7+ messages in thread
From: WeitaoWang-oc @ 2023-05-08 17:33 UTC (permalink / raw)
  To: Mathias Nyman, gregkh, mathias.nyman, linux-usb, linux-kernel
  Cc: tonywwang, weitaowang, stable

On 2023/5/8 17:01, Mathias Nyman wrote:
> On 6.5.2023 23.15, Weitao Wang wrote:
>> Add a quirk XHCI_ZHAOXIN_HOST for zhaoxin xhci to fix issues,
>> there are two cases will be used.
>> - add u1/u2 support.
>> - fix xHCI root hub speed show issue in zhaoxin platform.
>>
>> Add a quirk XHCI_ZHAOXIN_TRB_FETCH to fix TRB prefetch issue.
>>
>> On Zhaoxin ZX-100 project, xHCI can't work normally after resume
>> from system Sx state. To fix this issue, when resume from system
>> Sx state, reinitialize xHCI instead of restore.
>> So, Add XHCI_RESET_ON_RESUME quirk for ZX-100 to fix issue of
>> resuming from system Sx state.
>>
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
> 
> 
> I'd split this series into different logical parts:
> 
> patch 1/4
>    Set XHCI_RESET_ON_RESUME quirk to ZHAOXIN host to fix resume issue.
>    cc: stable
> 
> patch 2/4
>    Add XHCI_ZHAOXIN_TRB_FETCH quirk flag together with code that allocates double pages
>    cc: stable
> 
> patch 3/4
>    Add XHCI_ZHAOXIN_HOST quirk flag together with code that corrects USB3 roothub minor 
> version
>    cc: stable
> 
> patch 4/4
>    Set XHCI_LPM_SUPPORT quirk together with code that sets tier policy and u1/u2 timeouts,
>    Don't add stable as this is about adding feature support.
> 
Okay,no problem, I'll modify this patch series according to
above solution and order in the next version.

Best Regards,
Weitao
> (Accidentally replied to older v2 series with the above comments)
> 
> Thanks
> -Mathias
> 
> .

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

end of thread, other threads:[~2023-05-08  9:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-06 20:15 [PATCH v3 0/4] Fix some issues of xHCI for zhaoxin Weitao Wang
2023-05-06 20:15 ` [PATCH v3 1/4] xhci: Add some quirks for zhaoxin xhci to fix issues Weitao Wang
2023-05-08  9:01   ` Mathias Nyman
2023-05-08 17:33     ` WeitaoWang-oc
2023-05-06 20:15 ` [PATCH v3 2/4] xhci: fix issue of cross page boundary in TRB prefetch Weitao Wang
2023-05-06 20:15 ` [PATCH v3 3/4] xhci: Show zhaoxin xHCI root hub speed correctly Weitao Wang
2023-05-06 20:15 ` [PATCH v3 4/4] xhci: Add zhaoxin xHCI U1/U2 feature support Weitao Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).