All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/4] PCI/ASPM: Fix some L1 substate configuration
@ 2017-11-13 23:11 Bjorn Helgaas
  2017-11-13 23:11 ` [PATCH v1 1/4] PCI/ASPM: Account for downstream device's Port Common_Mode_Restore_Time Bjorn Helgaas
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Bjorn Helgaas @ 2017-11-13 23:11 UTC (permalink / raw)
  To: linux-pci; +Cc: Rajat Jain, linux-kernel, Vidya Sagar

The first two patches fix typos that cause incorrect L1 substate
configuration.  The last two are cosmetic for maintainability.

These are minor enough that I'd like to squeeze them into v4.15 unless
anybody objects.

---

Bjorn Helgaas (4):
      PCI/ASPM: Account for downstream device's Port Common_Mode_Restore_Time
      PCI/ASPM: Use correct capability pointer to program LTR_L1.2_THRESHOLD
      PCI/ASPM: Reformat ASPM register definitions
      PCI/ASPM: Add L1 Substates definitions


 drivers/pci/pcie/aspm.c       |   38 ++++++++++++++++++++++----------------
 include/uapi/linux/pci_regs.h |   34 ++++++++++++++++++++--------------
 2 files changed, 42 insertions(+), 30 deletions(-)

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

* [PATCH v1 1/4] PCI/ASPM: Account for downstream device's Port Common_Mode_Restore_Time
  2017-11-13 23:11 [PATCH v1 0/4] PCI/ASPM: Fix some L1 substate configuration Bjorn Helgaas
@ 2017-11-13 23:11 ` Bjorn Helgaas
  2017-11-13 23:12 ` [PATCH v1 2/4] PCI/ASPM: Use correct capability pointer to program LTR_L1.2_THRESHOLD Bjorn Helgaas
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Bjorn Helgaas @ 2017-11-13 23:11 UTC (permalink / raw)
  To: linux-pci; +Cc: Rajat Jain, linux-kernel, Vidya Sagar

From: Bjorn Helgaas <bhelgaas@google.com>

Every Port that supports the L1.2 substate advertises its Port
Common_Mode_Restore_Time, i.e., the time the Port requires to re-establish
common mode when exiting L1.2 (see PCIe r3.1, sec 7.33.2).

Per sec 5.5.3.3.1, when exiting L1.2, the Downstream Port (the device at
the upstream end of the link) must send TS1 training sequences for at least
T(COMMONMODE) after it detects electrical idle exit on the Link.  We want
this to be long enough for both ends of the Link, so we should set it to
the maximum of the Port Common_Mode_Restore_Time for the upstream and
downstream components on the Link.

Previously we only looked at the Port Common_Mode_Restore_Time of the
upstream device, so if the downstream device required more time, we didn't
program the upstream device's T(COMMONMODE) correctly.

Fixes: f1f0366dd6be ("PCI/ASPM: Calculate and save the L1.2 timing parameters")
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Rajat Jain <rajatja@google.com>
CC: stable@vger.kernel.org	# v4.11+
---
 drivers/pci/pcie/aspm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index 0bea8498b5a5..46c59afb8355 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -452,7 +452,7 @@ static void aspm_calc_l1ss_info(struct pcie_link_state *link,
 
 	/* Choose the greater of the two T_cmn_mode_rstr_time */
 	val1 = (upreg->l1ss_cap >> 8) & 0xFF;
-	val2 = (upreg->l1ss_cap >> 8) & 0xFF;
+	val2 = (dwreg->l1ss_cap >> 8) & 0xFF;
 	if (val1 > val2)
 		link->l1ss.ctl1 |= val1 << 8;
 	else

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

* [PATCH v1 2/4] PCI/ASPM: Use correct capability pointer to program LTR_L1.2_THRESHOLD
  2017-11-13 23:11 [PATCH v1 0/4] PCI/ASPM: Fix some L1 substate configuration Bjorn Helgaas
  2017-11-13 23:11 ` [PATCH v1 1/4] PCI/ASPM: Account for downstream device's Port Common_Mode_Restore_Time Bjorn Helgaas
@ 2017-11-13 23:12 ` Bjorn Helgaas
  2017-11-13 23:12 ` [PATCH v1 3/4] PCI/ASPM: Reformat ASPM register definitions Bjorn Helgaas
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Bjorn Helgaas @ 2017-11-13 23:12 UTC (permalink / raw)
  To: linux-pci; +Cc: Rajat Jain, linux-kernel, Vidya Sagar

From: Bjorn Helgaas <bhelgaas@google.com>

Previously we programmed the LTR_L1.2_THRESHOLD in the parent (upstream)
device using the capability pointer of the *child* (downstream) device,
which corrupted some random word of the parent's config space.

Use the parent's L1 SS capability pointer to program its
LTR_L1.2_THRESHOLD.

Fixes: aeda9adebab8 ("PCI/ASPM: Configure L1 substate settings")
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
CC: stable@vger.kernel.org	# v4.11+
CC: Rajat Jain <rajatja@google.com>
---
 drivers/pci/pcie/aspm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index 46c59afb8355..a378dd9d2473 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -657,7 +657,7 @@ static void pcie_config_aspm_l1ss(struct pcie_link_state *link, u32 state)
 					0xFF00, link->l1ss.ctl1);
 
 		/* Program LTR L1.2 threshold in both ports */
-		pci_clear_and_set_dword(parent,	dw_cap_ptr + PCI_L1SS_CTL1,
+		pci_clear_and_set_dword(parent,	up_cap_ptr + PCI_L1SS_CTL1,
 					0xE3FF0000, link->l1ss.ctl1);
 		pci_clear_and_set_dword(child, dw_cap_ptr + PCI_L1SS_CTL1,
 					0xE3FF0000, link->l1ss.ctl1);

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

* [PATCH v1 3/4] PCI/ASPM: Reformat ASPM register definitions
  2017-11-13 23:11 [PATCH v1 0/4] PCI/ASPM: Fix some L1 substate configuration Bjorn Helgaas
  2017-11-13 23:11 ` [PATCH v1 1/4] PCI/ASPM: Account for downstream device's Port Common_Mode_Restore_Time Bjorn Helgaas
  2017-11-13 23:12 ` [PATCH v1 2/4] PCI/ASPM: Use correct capability pointer to program LTR_L1.2_THRESHOLD Bjorn Helgaas
@ 2017-11-13 23:12 ` Bjorn Helgaas
  2017-11-13 23:12 ` [PATCH v1 4/4] PCI/ASPM: Add L1 Substates definitions Bjorn Helgaas
  2017-11-14 13:23 ` [PATCH v1 0/4] PCI/ASPM: Fix some L1 substate configuration Vidya Sagar
  4 siblings, 0 replies; 6+ messages in thread
From: Bjorn Helgaas @ 2017-11-13 23:12 UTC (permalink / raw)
  To: linux-pci; +Cc: Rajat Jain, linux-kernel, Vidya Sagar

From: Bjorn Helgaas <bhelgaas@google.com>

Reformat register field definitions in the style used elsewhere and align
comments with names used in the spec.  No functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 include/uapi/linux/pci_regs.h |   28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
index f8d58045926f..4150acb4cccb 100644
--- a/include/uapi/linux/pci_regs.h
+++ b/include/uapi/linux/pci_regs.h
@@ -995,19 +995,19 @@
 #define  PCI_PTM_CTRL_ENABLE		0x00000001  /* PTM enable */
 #define  PCI_PTM_CTRL_ROOT		0x00000002  /* Root select */
 
-/* L1 PM Substates */
-#define PCI_L1SS_CAP		    4	/* capability register */
-#define  PCI_L1SS_CAP_PCIPM_L1_2	 1	/* PCI PM L1.2 Support */
-#define  PCI_L1SS_CAP_PCIPM_L1_1	 2	/* PCI PM L1.1 Support */
-#define  PCI_L1SS_CAP_ASPM_L1_2		 4	/* ASPM L1.2 Support */
-#define  PCI_L1SS_CAP_ASPM_L1_1		 8	/* ASPM L1.1 Support */
-#define  PCI_L1SS_CAP_L1_PM_SS		16	/* L1 PM Substates Support */
-#define PCI_L1SS_CTL1		    8	/* Control Register 1 */
-#define  PCI_L1SS_CTL1_PCIPM_L1_2	1	/* PCI PM L1.2 Enable */
-#define  PCI_L1SS_CTL1_PCIPM_L1_1	2	/* PCI PM L1.1 Support */
-#define  PCI_L1SS_CTL1_ASPM_L1_2	4	/* ASPM L1.2 Support */
-#define  PCI_L1SS_CTL1_ASPM_L1_1	8	/* ASPM L1.1 Support */
-#define  PCI_L1SS_CTL1_L1SS_MASK	0x0000000F
-#define PCI_L1SS_CTL2		    0xC	/* Control Register 2 */
+/* ASPM L1 PM Substates */
+#define PCI_L1SS_CAP		0x04	/* Capabilities Register */
+#define  PCI_L1SS_CAP_PCIPM_L1_2	0x00000001  /* PCI-PM L1.2 Supported */
+#define  PCI_L1SS_CAP_PCIPM_L1_1	0x00000002  /* PCI-PM L1.1 Supported */
+#define  PCI_L1SS_CAP_ASPM_L1_2		0x00000004  /* ASPM L1.2 Supported */
+#define  PCI_L1SS_CAP_ASPM_L1_1		0x00000008  /* ASPM L1.1 Supported */
+#define  PCI_L1SS_CAP_L1_PM_SS		0x00000010  /* L1 PM Substates Supported */
+#define PCI_L1SS_CTL1		0x08	/* Control 1 Register */
+#define  PCI_L1SS_CTL1_PCIPM_L1_2	0x00000001  /* PCI-PM L1.2 Enable */
+#define  PCI_L1SS_CTL1_PCIPM_L1_1	0x00000002  /* PCI-PM L1.1 Enable */
+#define  PCI_L1SS_CTL1_ASPM_L1_2	0x00000004  /* ASPM L1.2 Enable */
+#define  PCI_L1SS_CTL1_ASPM_L1_1	0x00000008  /* ASPM L1.1 Enable */
+#define  PCI_L1SS_CTL1_L1SS_MASK	0x0000000f
+#define PCI_L1SS_CTL2		0x0c	/* Control 2 Register */
 
 #endif /* LINUX_PCI_REGS_H */

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

* [PATCH v1 4/4] PCI/ASPM: Add L1 Substates definitions
  2017-11-13 23:11 [PATCH v1 0/4] PCI/ASPM: Fix some L1 substate configuration Bjorn Helgaas
                   ` (2 preceding siblings ...)
  2017-11-13 23:12 ` [PATCH v1 3/4] PCI/ASPM: Reformat ASPM register definitions Bjorn Helgaas
@ 2017-11-13 23:12 ` Bjorn Helgaas
  2017-11-14 13:23 ` [PATCH v1 0/4] PCI/ASPM: Fix some L1 substate configuration Vidya Sagar
  4 siblings, 0 replies; 6+ messages in thread
From: Bjorn Helgaas @ 2017-11-13 23:12 UTC (permalink / raw)
  To: linux-pci; +Cc: Rajat Jain, linux-kernel, Vidya Sagar

From: Bjorn Helgaas <bhelgaas@google.com>

Add and use #defines for L1 Substate register fields instead of hard-coding
the masks.  Also update comments to use names from the spec.  No functional
change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/pcie/aspm.c       |   34 ++++++++++++++++++++--------------
 include/uapi/linux/pci_regs.h |    6 ++++++
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index a378dd9d2473..d240ffab24c1 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -450,24 +450,25 @@ static void aspm_calc_l1ss_info(struct pcie_link_state *link,
 	if (!(link->aspm_support & ASPM_STATE_L1_2_MASK))
 		return;
 
-	/* Choose the greater of the two T_cmn_mode_rstr_time */
-	val1 = (upreg->l1ss_cap >> 8) & 0xFF;
-	val2 = (dwreg->l1ss_cap >> 8) & 0xFF;
+	/* Choose the greater of the two Port Common_Mode_Restore_Times */
+	val1 = (upreg->l1ss_cap & PCI_L1SS_CAP_CM_RESTORE_TIME) >> 8;
+	val2 = (dwreg->l1ss_cap & PCI_L1SS_CAP_CM_RESTORE_TIME) >> 8;
 	if (val1 > val2)
 		link->l1ss.ctl1 |= val1 << 8;
 	else
 		link->l1ss.ctl1 |= val2 << 8;
+
 	/*
 	 * We currently use LTR L1.2 threshold to be fixed constant picked from
 	 * Intel's coreboot.
 	 */
 	link->l1ss.ctl1 |= LTR_L1_2_THRESHOLD_BITS;
 
-	/* Choose the greater of the two T_pwr_on */
-	val1 = (upreg->l1ss_cap >> 19) & 0x1F;
-	scale1 = (upreg->l1ss_cap >> 16) & 0x03;
-	val2 = (dwreg->l1ss_cap >> 19) & 0x1F;
-	scale2 = (dwreg->l1ss_cap >> 16) & 0x03;
+	/* Choose the greater of the two Port T_POWER_ON times */
+	val1   = (upreg->l1ss_cap & PCI_L1SS_CAP_P_PWR_ON_VALUE) >> 19;
+	scale1 = (upreg->l1ss_cap & PCI_L1SS_CAP_P_PWR_ON_SCALE) >> 16;
+	val2   = (dwreg->l1ss_cap & PCI_L1SS_CAP_P_PWR_ON_VALUE) >> 19;
+	scale2 = (dwreg->l1ss_cap & PCI_L1SS_CAP_P_PWR_ON_SCALE) >> 16;
 
 	if (calc_l1ss_pwron(link->pdev, scale1, val1) >
 	    calc_l1ss_pwron(link->downstream, scale2, val2))
@@ -646,21 +647,26 @@ static void pcie_config_aspm_l1ss(struct pcie_link_state *link, u32 state)
 
 	if (enable_req & ASPM_STATE_L1_2_MASK) {
 
-		/* Program T_pwr_on in both ports */
+		/* Program T_POWER_ON times in both ports */
 		pci_write_config_dword(parent, up_cap_ptr + PCI_L1SS_CTL2,
 				       link->l1ss.ctl2);
 		pci_write_config_dword(child, dw_cap_ptr + PCI_L1SS_CTL2,
 				       link->l1ss.ctl2);
 
-		/* Program T_cmn_mode in parent */
+		/* Program Common_Mode_Restore_Time in upstream device */
 		pci_clear_and_set_dword(parent, up_cap_ptr + PCI_L1SS_CTL1,
-					0xFF00, link->l1ss.ctl1);
+					PCI_L1SS_CTL1_CM_RESTORE_TIME,
+					link->l1ss.ctl1);
 
-		/* Program LTR L1.2 threshold in both ports */
+		/* Program LTR_L1.2_THRESHOLD time in both ports */
 		pci_clear_and_set_dword(parent,	up_cap_ptr + PCI_L1SS_CTL1,
-					0xE3FF0000, link->l1ss.ctl1);
+					PCI_L1SS_CTL1_LTR_L12_TH_VALUE |
+					PCI_L1SS_CTL1_LTR_L12_TH_SCALE,
+					link->l1ss.ctl1);
 		pci_clear_and_set_dword(child, dw_cap_ptr + PCI_L1SS_CTL1,
-					0xE3FF0000, link->l1ss.ctl1);
+					PCI_L1SS_CTL1_LTR_L12_TH_VALUE |
+					PCI_L1SS_CTL1_LTR_L12_TH_SCALE,
+					link->l1ss.ctl1);
 	}
 
 	val = 0;
diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
index 4150acb4cccb..85a4014de42e 100644
--- a/include/uapi/linux/pci_regs.h
+++ b/include/uapi/linux/pci_regs.h
@@ -1002,12 +1002,18 @@
 #define  PCI_L1SS_CAP_ASPM_L1_2		0x00000004  /* ASPM L1.2 Supported */
 #define  PCI_L1SS_CAP_ASPM_L1_1		0x00000008  /* ASPM L1.1 Supported */
 #define  PCI_L1SS_CAP_L1_PM_SS		0x00000010  /* L1 PM Substates Supported */
+#define  PCI_L1SS_CAP_CM_RESTORE_TIME	0x0000ff00  /* Port Common_Mode_Restore_Time */
+#define  PCI_L1SS_CAP_P_PWR_ON_SCALE	0x00030000  /* Port T_POWER_ON scale */
+#define  PCI_L1SS_CAP_P_PWR_ON_VALUE	0x00f80000  /* Port T_POWER_ON value */
 #define PCI_L1SS_CTL1		0x08	/* Control 1 Register */
 #define  PCI_L1SS_CTL1_PCIPM_L1_2	0x00000001  /* PCI-PM L1.2 Enable */
 #define  PCI_L1SS_CTL1_PCIPM_L1_1	0x00000002  /* PCI-PM L1.1 Enable */
 #define  PCI_L1SS_CTL1_ASPM_L1_2	0x00000004  /* ASPM L1.2 Enable */
 #define  PCI_L1SS_CTL1_ASPM_L1_1	0x00000008  /* ASPM L1.1 Enable */
 #define  PCI_L1SS_CTL1_L1SS_MASK	0x0000000f
+#define  PCI_L1SS_CTL1_CM_RESTORE_TIME	0x0000ff00  /* Common_Mode_Restore_Time */
+#define  PCI_L1SS_CTL1_LTR_L12_TH_VALUE	0x03ff0000  /* LTR_L1.2_THRESHOLD_Value */
+#define  PCI_L1SS_CTL1_LTR_L12_TH_SCALE	0xe0000000  /* LTR_L1.2_THRESHOLD_Scale */
 #define PCI_L1SS_CTL2		0x0c	/* Control 2 Register */
 
 #endif /* LINUX_PCI_REGS_H */

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

* Re: [PATCH v1 0/4] PCI/ASPM: Fix some L1 substate configuration
  2017-11-13 23:11 [PATCH v1 0/4] PCI/ASPM: Fix some L1 substate configuration Bjorn Helgaas
                   ` (3 preceding siblings ...)
  2017-11-13 23:12 ` [PATCH v1 4/4] PCI/ASPM: Add L1 Substates definitions Bjorn Helgaas
@ 2017-11-14 13:23 ` Vidya Sagar
  4 siblings, 0 replies; 6+ messages in thread
From: Vidya Sagar @ 2017-11-14 13:23 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci; +Cc: Rajat Jain, linux-kernel


On Tuesday 14 November 2017 04:41 AM, Bjorn Helgaas wrote:
> The first two patches fix typos that cause incorrect L1 substate
> configuration.  The last two are cosmetic for maintainability.
>
> These are minor enough that I'd like to squeeze them into v4.15 unless
> anybody objects.
>
> ---
>
> Bjorn Helgaas (4):
>        PCI/ASPM: Account for downstream device's Port Common_Mode_Restore_Time
>        PCI/ASPM: Use correct capability pointer to program LTR_L1.2_THRESHOLD
>        PCI/ASPM: Reformat ASPM register definitions
>        PCI/ASPM: Add L1 Substates definitions
>
>
>   drivers/pci/pcie/aspm.c       |   38 ++++++++++++++++++++++----------------
>   include/uapi/linux/pci_regs.h |   34 ++++++++++++++++++++--------------
>   2 files changed, 42 insertions(+), 30 deletions(-)
Reviewed-by: Vidya Sagar <vidyas@nvidia.com>

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

end of thread, other threads:[~2017-11-14 13:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-13 23:11 [PATCH v1 0/4] PCI/ASPM: Fix some L1 substate configuration Bjorn Helgaas
2017-11-13 23:11 ` [PATCH v1 1/4] PCI/ASPM: Account for downstream device's Port Common_Mode_Restore_Time Bjorn Helgaas
2017-11-13 23:12 ` [PATCH v1 2/4] PCI/ASPM: Use correct capability pointer to program LTR_L1.2_THRESHOLD Bjorn Helgaas
2017-11-13 23:12 ` [PATCH v1 3/4] PCI/ASPM: Reformat ASPM register definitions Bjorn Helgaas
2017-11-13 23:12 ` [PATCH v1 4/4] PCI/ASPM: Add L1 Substates definitions Bjorn Helgaas
2017-11-14 13:23 ` [PATCH v1 0/4] PCI/ASPM: Fix some L1 substate configuration Vidya Sagar

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.