Skip to contentSkip to conversation

usb: xhci: tegra: Add shutdown callback for Tegra XUSB

PATCH Superseded Haotien Hsu 4 participants 5 messages Jul 18, 2023 – Jul 27, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 usb: xhci: tegra: Add shutdown callback for Tegra XUSB

From: Henry Lin <[email protected]>

If memory accesses by the Tegra XUSB controller are translated through the SMMU (System MMU), the hardware may continue accessing memory even after the SMMU translations have been disabled during the shutdown process and this can in turn cause unpredictable crashes. Fix this by adding a shutdown implementation that ensures the hardware is turned off during system reboot or shutdown.

---
V1 -> V2: Resend for the typo in the mailing list

---
 drivers/usb/host/xhci-tegra.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/usb/host/xhci-tegra.c +21 -7
index a56cc81b9404..6ef2eac9835d 100644
@@ -1925,6 +1925,15 @@ static int tegra_xusb_probe(struct platform_device *pdev)
 	return err;
 }
 
+static void tegra_xusb_disable(struct tegra_xusb *tegra)
+{
+	tegra_xusb_powergate_partitions(tegra);
+	tegra_xusb_powerdomain_remove(tegra->dev, tegra);
+	tegra_xusb_phy_disable(tegra);
+	tegra_xusb_clk_disable(tegra);
+	regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
+}
+
 static int tegra_xusb_remove(struct platform_device *pdev)
 {
 	struct tegra_xusb *tegra = platform_get_drvdata(pdev);
@@ -1947,18 +1956,22 @@ static int tegra_xusb_remove(struct platform_device *pdev)
 
 	pm_runtime_put(&pdev->dev);
 
-	tegra_xusb_powergate_partitions(tegra);
-
-	tegra_xusb_powerdomain_remove(&pdev->dev, tegra);
-
-	tegra_xusb_phy_disable(tegra);
-	tegra_xusb_clk_disable(tegra);
-	regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
+	tegra_xusb_disable(tegra);
 	tegra_xusb_padctl_put(tegra->padctl);
 
 	return 0;
 }
 
+static void tegra_xusb_shutdown(struct platform_device *pdev)
+{
+	struct tegra_xusb *tegra = platform_get_drvdata(pdev);
+
+	pm_runtime_get_sync(&pdev->dev);
+	disable_irq(tegra->xhci_irq);
+	xhci_shutdown(tegra->hcd);
+	tegra_xusb_disable(tegra);
+}
+
 static bool xhci_hub_ports_suspended(struct xhci_hub *hub)
 {
 	struct device *dev = hub->hcd->self.controller;
@@ -2666,6 +2679,7 @@ MODULE_DEVICE_TABLE(of, tegra_xusb_of_match);
 static struct platform_driver tegra_xusb_driver = {
 	.probe = tegra_xusb_probe,
 	.remove = tegra_xusb_remove,
+	.shutdown = tegra_xusb_shutdown,
 	.driver = {
 		.name = "tegra-xusb",
 		.pm = &tegra_xusb_pm_ops,
Signature · 1 line
2.25.1
#1 lore raw
Quoted 51 lines · Haotien Hsu

From: Henry Lin <[email protected]>

If memory accesses by the Tegra XUSB controller are translated through the SMMU (System MMU), the hardware may continue accessing memory even after the SMMU translations have been disabled during the shutdown process and this can in turn cause unpredictable crashes. Fix this by adding a shutdown implementation that ensures the hardware is turned off during system reboot or shutdown.

---
V1 -> V2: Resend for the typo in the mailing list

---
  drivers/usb/host/xhci-tegra.c | 28 +++++++++++++++++++++-------
  1 file changed, 21 insertions(+), 7 deletions(-)
drivers/usb/host/xhci-tegra.c +10 -7
index a56cc81b9404..6ef2eac9835d 100644
@@ -1925,6 +1925,15 @@ static int tegra_xusb_probe(struct platform_device *pdev)
  	return err;
  }
 
+static void tegra_xusb_disable(struct tegra_xusb *tegra)
+{
+	tegra_xusb_powergate_partitions(tegra);
+	tegra_xusb_powerdomain_remove(tegra->dev, tegra);
+	tegra_xusb_phy_disable(tegra);
+	tegra_xusb_clk_disable(tegra);
+	regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
+}
+
  static int tegra_xusb_remove(struct platform_device *pdev)
  {
  	struct tegra_xusb *tegra = platform_get_drvdata(pdev);
@@ -1947,18 +1956,22 @@ static int tegra_xusb_remove(struct platform_device *pdev)
 
  	pm_runtime_put(&pdev->dev);
 
-	tegra_xusb_powergate_partitions(tegra);
-
-	tegra_xusb_powerdomain_remove(&pdev->dev, tegra);
-
-	tegra_xusb_phy_disable(tegra);
-	tegra_xusb_clk_disable(tegra);
-	regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
+	tegra_xusb_disable(tegra);

drivers/usb/host/xhci-tegra.c static int tegra_xusb_remove(struct platform_device *pdev) · line 1969

Quoted 10 lines
drivers/usb/host/xhci-tegra.c +5 -0
  	tegra_xusb_padctl_put(tegra->padctl);
 
  	return 0;
  }
 
+static void tegra_xusb_shutdown(struct platform_device *pdev)
+{
+	struct tegra_xusb *tegra = platform_get_drvdata(pdev);
+
+	pm_runtime_get_sync(&pdev->dev);

Where is this balanced?

Regards
Oliver

#2 lore raw
Quoted 53 lines · Oliver Neukum
Quoted 50 lines · Haotien Hsu

From: Henry Lin <[email protected]>

If memory accesses by the Tegra XUSB controller are translated through the SMMU (System MMU), the hardware may continue accessing memory even after the SMMU translations have been disabled during the shutdown process and this can in turn cause unpredictable crashes. Fix this by adding a shutdown implementation that ensures the hardware is turned off during system reboot or shutdown.

---
V1 -> V2: Resend for the typo in the mailing list

---
  drivers/usb/host/xhci-tegra.c | 28 +++++++++++++++++++++-------
  1 file changed, 21 insertions(+), 7 deletions(-)
drivers/usb/host/xhci-tegra.c +10 -7
index a56cc81b9404..6ef2eac9835d 100644
@@ -1925,6 +1925,15 @@ static int tegra_xusb_probe(struct platform_device *pdev)
  	return err;
  }
+static void tegra_xusb_disable(struct tegra_xusb *tegra)
+{
+	tegra_xusb_powergate_partitions(tegra);
+	tegra_xusb_powerdomain_remove(tegra->dev, tegra);
+	tegra_xusb_phy_disable(tegra);
+	tegra_xusb_clk_disable(tegra);
+	regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
+}
+
  static int tegra_xusb_remove(struct platform_device *pdev)
  {
  	struct tegra_xusb *tegra = platform_get_drvdata(pdev);
@@ -1947,18 +1956,22 @@ static int tegra_xusb_remove(struct platform_device *pdev)
  	pm_runtime_put(&pdev->dev);
-	tegra_xusb_powergate_partitions(tegra);
-
-	tegra_xusb_powerdomain_remove(&pdev->dev, tegra);
-
-	tegra_xusb_phy_disable(tegra);
-	tegra_xusb_clk_disable(tegra);
-	regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
+	tegra_xusb_disable(tegra);
  	tegra_xusb_padctl_put(tegra->padctl);
  	return 0;
Quoted 8 lines

drivers/usb/host/xhci-tegra.c static int tegra_xusb_remove(struct platform_device *pdev) · line 1969

Quoted 6 lines
drivers/usb/host/xhci-tegra.c +5 -0
  }
+static void tegra_xusb_shutdown(struct platform_device *pdev)
+{
+	struct tegra_xusb *tegra = platform_get_drvdata(pdev);
+
+	pm_runtime_get_sync(&pdev->dev);

Where is this balanced?

Well, I suppose we could add a pm_runtime_put() at the end of this function, but since we expect the system to shut down after this, at which point any runtime PM accounting is going to go bye-bye anyway, do we really want to bother?

Thierry

#3 lore raw
In reply to Haotien Hsu
Quoted 13 lines · Haotien Hsu

From: Henry Lin <[email protected]>

If memory accesses by the Tegra XUSB controller are translated through the SMMU (System MMU), the hardware may continue accessing memory even after the SMMU translations have been disabled during the shutdown process and this can in turn cause unpredictable crashes. Fix this by adding a shutdown implementation that ensures the hardware is turned off during system reboot or shutdown.

Quoted 5 lines

---
V1 -> V2: Resend for the typo in the mailing list

---
 drivers/usb/host/xhci-tegra.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

Does not apply against 6.5-rc4 at all :(

#4 lore raw
Quoted 20 lines · Greg Kroah-Hartman

External email: Use caution opening links or attachments

Quoted 16 lines · Haotien Hsu

From: Henry Lin <[email protected]>

If memory accesses by the Tegra XUSB controller are translated through
the SMMU (System MMU), the hardware may continue accessing memory even
after the SMMU translations have been disabled during the shutdown process and this can in turn cause unpredictable crashes. Fix this by adding a shutdown implementation that ensures the hardware
is turned off during system reboot or shutdown.

Quoted 7 lines
Quoted 5 lines

---
V1 -> V2: Resend for the typo in the mailing list

---
 drivers/usb/host/xhci-tegra.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

Does not apply against 6.5-rc4 at all :(

I rebased the patch and sent it again.
I am sorry about that.