All of lore.kernel.org
 help / color / mirror / Atom feed
From: Victor Ding <victording@google.com>
To: Ulf Hansson <ulf.hansson@linaro.org>,
	Adrian Hunter <adrian.hunter@intel.com>
Cc: Ben Chuang <ben.chuang@genesyslogic.com.tw>,
	Bjorn Helgaas <helgaas@kernel.org>,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	linux-mmc@vger.kernel.org, Victor Ding <victording@google.com>
Subject: [PATCH 2/2] mmc: sdhci-pci-gli: Disable ASPM during a suspension
Date: Tue, 12 Jan 2021 04:02:05 +0000	[thread overview]
Message-ID: <20210112040146.2.Ic902bbd9f04e2d82ac578411e7fafc77b6c750e2@changeid> (raw)
In-Reply-To: <20210112040205.4117303-1-victording@google.com>

GL9750 has a 3100us PortTPowerOnTime; however, it enters L1.2 after
only ~4us inactivity per PCIe trace. During a suspend/resume process,
PCI access operations are frequently longer than 4us apart.
Therefore, the device frequently enters and leaves L1.2 during this
process, causing longer than desirable suspend/resume time. The total
time cost due to this L1.2 exit latency could add up to ~200ms.

Considering that PCI access operations are fairly close to each other
(though sometimes > 4us), the actual time the device could stay in
L1.2 is negligible. Therefore, the little power-saving benefit from
ASPM during suspend/resume does not overweight the performance
degradation caused by long L1.2 exit latency.

Therefore, this patch proposes to disable ASPM during a suspend/resume
process.

Signed-off-by: Victor Ding <victording@google.com>
---

 drivers/mmc/host/sdhci-pci-core.c |  2 +-
 drivers/mmc/host/sdhci-pci-gli.c  | 46 +++++++++++++++++++++++++++++--
 drivers/mmc/host/sdhci-pci.h      |  1 +
 3 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
index 9552708846ca..fd7544a498c0 100644
--- a/drivers/mmc/host/sdhci-pci-core.c
+++ b/drivers/mmc/host/sdhci-pci-core.c
@@ -67,7 +67,7 @@ static int sdhci_pci_init_wakeup(struct sdhci_pci_chip *chip)
 	return 0;
 }
 
-static int sdhci_pci_suspend_host(struct sdhci_pci_chip *chip)
+int sdhci_pci_suspend_host(struct sdhci_pci_chip *chip)
 {
 	int i, ret;
 
diff --git a/drivers/mmc/host/sdhci-pci-gli.c b/drivers/mmc/host/sdhci-pci-gli.c
index 9887485a4134..c7b788b0e22e 100644
--- a/drivers/mmc/host/sdhci-pci-gli.c
+++ b/drivers/mmc/host/sdhci-pci-gli.c
@@ -109,6 +109,12 @@
 
 #define GLI_MAX_TUNING_LOOP 40
 
+#ifdef CONFIG_PM_SLEEP
+struct gli_host {
+	u16 linkctl_saved;
+};
+#endif
+
 /* Genesys Logic chipset */
 static inline void gl9750_wt_on(struct sdhci_host *host)
 {
@@ -577,14 +583,48 @@ static u32 sdhci_gl9750_readl(struct sdhci_host *host, int reg)
 }
 
 #ifdef CONFIG_PM_SLEEP
+static int sdhci_pci_gli_suspend(struct sdhci_pci_chip *chip)
+{
+	int ret;
+	struct sdhci_pci_slot *slot = chip->slots[0];
+	struct pci_dev *pdev = slot->chip->pdev;
+	struct gli_host *gli_host = sdhci_pci_priv(slot);
+
+	ret = pcie_capability_read_word(pdev, PCI_EXP_LNKCTL,
+			&gli_host->linkctl_saved);
+	if (ret)
+		goto exit;
+
+	ret = pcie_capability_write_word(pdev, PCI_EXP_LNKCTL,
+			gli_host->linkctl_saved & ~PCI_EXP_LNKCTL_ASPMC);
+	if (ret)
+		goto exit;
+
+	ret = sdhci_pci_suspend_host(chip);
+
+exit:
+	return ret;
+}
+
 static int sdhci_pci_gli_resume(struct sdhci_pci_chip *chip)
 {
+	int ret;
 	struct sdhci_pci_slot *slot = chip->slots[0];
+	struct pci_dev *pdev = slot->chip->pdev;
+	struct gli_host *gli_host = sdhci_pci_priv(slot);
 
-	pci_free_irq_vectors(slot->chip->pdev);
+	pci_free_irq_vectors(pdev);
 	gli_pcie_enable_msi(slot);
 
-	return sdhci_pci_resume_host(chip);
+	ret = sdhci_pci_resume_host(chip);
+	if (ret)
+		goto exit;
+
+	ret = pcie_capability_clear_and_set_word(pdev, PCI_EXP_LNKCTL,
+			PCI_EXP_LNKCTL_ASPMC, gli_host->linkctl_saved);
+
+exit:
+	return ret;
 }
 
 static int sdhci_cqhci_gli_resume(struct sdhci_pci_chip *chip)
@@ -834,7 +874,9 @@ const struct sdhci_pci_fixes sdhci_gl9750 = {
 	.probe_slot	= gli_probe_slot_gl9750,
 	.ops            = &sdhci_gl9750_ops,
 #ifdef CONFIG_PM_SLEEP
+	.suspend        = sdhci_pci_gli_suspend,
 	.resume         = sdhci_pci_gli_resume,
+	.priv_size      = sizeof(struct gli_host),
 #endif
 };
 
diff --git a/drivers/mmc/host/sdhci-pci.h b/drivers/mmc/host/sdhci-pci.h
index d0ed232af0eb..16187a265e63 100644
--- a/drivers/mmc/host/sdhci-pci.h
+++ b/drivers/mmc/host/sdhci-pci.h
@@ -187,6 +187,7 @@ static inline void *sdhci_pci_priv(struct sdhci_pci_slot *slot)
 }
 
 #ifdef CONFIG_PM_SLEEP
+int sdhci_pci_suspend_host(struct sdhci_pci_chip *chip);
 int sdhci_pci_resume_host(struct sdhci_pci_chip *chip);
 #endif
 int sdhci_pci_enable_dma(struct sdhci_host *host);
-- 
2.30.0.284.gd98b1dd5eaa7-goog


  parent reply	other threads:[~2021-01-12  4:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-12  4:02 [PATCH 0/2] Disable ASPM on GL9750 during a suspension Victor Ding
2021-01-12  4:02 ` [PATCH 1/2] PCI/ASPM: Disable ASPM until its LTR and L1ss state is restored Victor Ding
2021-01-12 22:32   ` Bjorn Helgaas
2021-01-13  2:16     ` Victor Ding
2021-01-13 20:54       ` Bjorn Helgaas
2021-01-14  9:13         ` Victor Ding
2021-01-12  4:02 ` Victor Ding [this message]
2021-01-12 22:38   ` [PATCH 2/2] mmc: sdhci-pci-gli: Disable ASPM during a suspension Bjorn Helgaas
2021-01-13  2:16     ` Victor Ding
2021-01-13 21:48       ` Bjorn Helgaas
2021-01-14  9:13         ` Victor Ding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210112040146.2.Ic902bbd9f04e2d82ac578411e7fafc77b6c750e2@changeid \
    --to=victording@google.com \
    --cc=adrian.hunter@intel.com \
    --cc=ben.chuang@genesyslogic.com.tw \
    --cc=helgaas@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.