* [Linux-kernel-mentees] [PATCH] PCI: Add support for LTR
@ 2020-08-21 19:13 Puranjay Mohan
2020-08-21 21:56 ` kernel test robot
2020-08-21 22:32 ` kernel test robot
0 siblings, 2 replies; 3+ messages in thread
From: Puranjay Mohan @ 2020-08-21 19:13 UTC (permalink / raw)
To: bjorn; +Cc: linux-pci, linux-kernel-mentees, Puranjay Mohan
Add a new function pci_ltr_init() which will be called from
pci_init_capabilities() to initialize every PCIe device's LTR values.
Add code in probe.c to evaluate LTR _DSM and save the latencies in pci_dev.
Signed-off-by: Puranjay Mohan <puranjay12@gmail.com>
---
drivers/pci/pci-acpi.c | 28 ++++++++++++++++++++++++++++
drivers/pci/pci.c | 26 ++++++++++++++++++++++++++
drivers/pci/pci.h | 5 +++++
drivers/pci/probe.c | 6 ++++++
include/linux/pci-acpi.h | 1 +
include/linux/pci.h | 2 ++
6 files changed, 68 insertions(+)
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 7224b1e5f2a8..c9151f96f3c9 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -1213,6 +1213,34 @@ static void pci_acpi_optimize_delay(struct pci_dev *pdev,
ACPI_FREE(obj);
}
+/* pci_acpi_evaluate_ltr_latency
+ *
+ * @dev - the pci_dev to evaluate and save latencies
+ */
+void pci_acpi_evaluate_ltr_latency(struct pci_dev *dev)
+{
+ union acpi_object *obj, *elements;
+ struct acpi_device *handle;
+
+ handle = ACPI_HANDLE(&dev->dev);
+ if (!handle)
+ return;
+
+ obj = acpi_evaluate_dsm(handle, &pci_acpi_dsm_guid, 0x2,
+ DSM_PCI_LTR_MAX_LATENCY, NULL);
+ if (!obj)
+ return;
+
+ if (obj->type == ACPI_TYPE_PACKAGE && obj->package.count == 4) {
+ elements = obj->package.elements;
+ dev->max_snoop_latency = (u16)elements[1].integer.value |
+ ((u16)elements[0].integer.value << PCI_LTR_SCALE_SHIFT);
+ dev->max_nosnoop_latency = (u16)elements[3].integer.value |
+ ((u16)elements[2].integer.value << PCI_LTR_SCALE_SHIFT);
+ }
+ ACPI_FREE(obj);
+}
+
static void pci_acpi_set_untrusted(struct pci_dev *dev)
{
u8 val;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index c9338f914a0e..8aa71175ebea 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -2921,6 +2921,32 @@ void pci_pm_init(struct pci_dev *dev)
dev->imm_ready = 1;
}
+/**
+ * pci_ltr_init - Initialize Latency Tolerance Information of given PCI device
+ * @dev: PCI device to handle.
+ */
+void pci_ltr_init(struct pci_dev *dev)
+{
+#ifdef CONFIG_PCIASPM
+ int ltr;
+ struct pci_dev *endpoint_dev = dev;
+ u16 max_snoop_sum = 0;
+ u16 max_nosnoop_sum = 0;
+
+ ltr = pci_find_ext_capability(endpoint_dev, PCI_EXT_CAP_ID_LTR);
+ if (!ltr)
+ return;
+
+ dev = pci_upstream_bridge(dev);
+ while (dev) {
+ max_snoop_sum += dev->max_snoop_latency;
+ max_nosnoop_sum += dev->max_nosnoop_latency;
+ dev = pci_upstream_bridge(dev);
+ }
+ pci_write_config_word(endpoint_dev, ltr + PCI_LTR_MAX_SNOOP_LAT, max_snoop_sum);
+ pci_write_config_word(endpoint_dev, ltr + PCI_LTR_MAX_NOSNOOP_LAT, max_nosnoop_sum);
+#endif
+}
static unsigned long pci_ea_flags(struct pci_dev *dev, u8 prop)
{
unsigned long flags = IORESOURCE_PCI_FIXED | IORESOURCE_PCI_EA_BEI;
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 6d3f75867106..f824dd977dd3 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -109,6 +109,7 @@ void pci_free_cap_save_buffers(struct pci_dev *dev);
bool pci_bridge_d3_possible(struct pci_dev *dev);
void pci_bridge_d3_update(struct pci_dev *dev);
void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev);
+void pci_ltr_init(struct pci_dev *dev);
static inline void pci_wakeup_event(struct pci_dev *dev)
{
@@ -673,11 +674,15 @@ static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL
#ifdef CONFIG_ACPI
int pci_acpi_program_hp_params(struct pci_dev *dev);
+void pci_acpi_evaluate_ltr_latency(struct pci_dev *dev);
#else
static inline int pci_acpi_program_hp_params(struct pci_dev *dev)
{
return -ENODEV;
}
+static inline void pci_acpi_evaluate_ltr_latency(struct pci_dev *dev)
+{
+}
#endif
#ifdef CONFIG_PCIEASPM
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 2f66988cea25..0bc9d7e6a0e9 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2134,6 +2134,11 @@ static void pci_configure_ltr(struct pci_dev *dev)
dev->ltr_path = 1;
}
#endif
+
+ /*
+ * Read latency values from _DSM and save in pci_dev
+ */
+ pci_acpi_evaluate_ltr_latency(dev);
}
static void pci_configure_eetlp_prefix(struct pci_dev *dev)
@@ -2394,6 +2399,7 @@ static void pci_init_capabilities(struct pci_dev *dev)
pci_ptm_init(dev); /* Precision Time Measurement */
pci_aer_init(dev); /* Advanced Error Reporting */
pci_dpc_init(dev); /* Downstream Port Containment */
+ pci_ltr_init(dev); /* Latency Tolerance Reporting */
pcie_report_downtraining(dev);
diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h
index 5ba475ca9078..e23236a4ff66 100644
--- a/include/linux/pci-acpi.h
+++ b/include/linux/pci-acpi.h
@@ -110,6 +110,7 @@ extern const guid_t pci_acpi_dsm_guid;
/* _DSM Definitions for PCI */
#define DSM_PCI_PRESERVE_BOOT_CONFIG 0x05
+#define DSM_PCI_LTR_MAX_LATENCY 0x06
#define DSM_PCI_DEVICE_NAME 0x07
#define DSM_PCI_POWER_ON_RESET_DELAY 0x08
#define DSM_PCI_DEVICE_READINESS_DURATIONS 0x09
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 34c1c4f45288..e407c8cba2d3 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -380,6 +380,8 @@ struct pci_dev {
struct pcie_link_state *link_state; /* ASPM link state */
unsigned int ltr_path:1; /* Latency Tolerance Reporting
supported from root to here */
+ u16 max_snoop_latency; /* LTR Max Snoop latency */
+ u16 max_nosnoop_latency; /* LTR Max No Snoop latency */
#endif
unsigned int eetlp_prefix_path:1; /* End-to-End TLP Prefix */
--
2.27.0
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] PCI: Add support for LTR
2020-08-21 19:13 [Linux-kernel-mentees] [PATCH] PCI: Add support for LTR Puranjay Mohan
@ 2020-08-21 21:56 ` kernel test robot
2020-08-21 22:32 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2020-08-21 21:56 UTC (permalink / raw)
To: Puranjay Mohan, bjorn
Cc: linux-pci, linux-kernel-mentees, kbuild-all, Puranjay Mohan
[-- Attachment #1: Type: text/plain, Size: 2838 bytes --]
Hi Puranjay,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on v5.8]
[cannot apply to pci/next pm/linux-next v5.9-rc1 next-20200821]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Puranjay-Mohan/PCI-Add-support-for-LTR/20200822-031519
base: bcf876870b95592b52519ed4aafcf9d95999bc9c
config: x86_64-randconfig-s022-20200820 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.2-191-g10164920-dirty
# save the attached .config to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
drivers/pci/pci-acpi.c: In function 'pci_acpi_evaluate_ltr_latency':
>> drivers/pci/pci-acpi.c:1236:6: error: 'struct pci_dev' has no member named 'max_snoop_latency'
1236 | dev->max_snoop_latency = (u16)elements[1].integer.value |
| ^~
>> drivers/pci/pci-acpi.c:1238:6: error: 'struct pci_dev' has no member named 'max_nosnoop_latency'
1238 | dev->max_nosnoop_latency = (u16)elements[3].integer.value |
| ^~
# https://github.com/0day-ci/linux/commit/2aef8c301151afccc59ac8c0ad321f4e0f77d453
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Puranjay-Mohan/PCI-Add-support-for-LTR/20200822-031519
git checkout 2aef8c301151afccc59ac8c0ad321f4e0f77d453
vim +1236 drivers/pci/pci-acpi.c
1215
1216 /* pci_acpi_evaluate_ltr_latency
1217 *
1218 * @dev - the pci_dev to evaluate and save latencies
1219 */
1220 void pci_acpi_evaluate_ltr_latency(struct pci_dev *dev)
1221 {
1222 union acpi_object *obj, *elements;
1223 struct acpi_device *handle;
1224
1225 handle = ACPI_HANDLE(&dev->dev);
1226 if (!handle)
1227 return;
1228
1229 obj = acpi_evaluate_dsm(handle, &pci_acpi_dsm_guid, 0x2,
1230 DSM_PCI_LTR_MAX_LATENCY, NULL);
1231 if (!obj)
1232 return;
1233
1234 if (obj->type == ACPI_TYPE_PACKAGE && obj->package.count == 4) {
1235 elements = obj->package.elements;
> 1236 dev->max_snoop_latency = (u16)elements[1].integer.value |
1237 ((u16)elements[0].integer.value << PCI_LTR_SCALE_SHIFT);
> 1238 dev->max_nosnoop_latency = (u16)elements[3].integer.value |
1239 ((u16)elements[2].integer.value << PCI_LTR_SCALE_SHIFT);
1240 }
1241 ACPI_FREE(obj);
1242 }
1243
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 29866 bytes --]
[-- Attachment #3: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH] PCI: Add support for LTR
2020-08-21 19:13 [Linux-kernel-mentees] [PATCH] PCI: Add support for LTR Puranjay Mohan
2020-08-21 21:56 ` kernel test robot
@ 2020-08-21 22:32 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2020-08-21 22:32 UTC (permalink / raw)
To: Puranjay Mohan, bjorn
Cc: kbuild-all, Puranjay Mohan, linux-pci, clang-built-linux,
linux-kernel-mentees
[-- Attachment #1: Type: text/plain, Size: 3076 bytes --]
Hi Puranjay,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on v5.8]
[cannot apply to pci/next pm/linux-next v5.9-rc1 next-20200821]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Puranjay-Mohan/PCI-Add-support-for-LTR/20200822-031519
base: bcf876870b95592b52519ed4aafcf9d95999bc9c
config: x86_64-randconfig-a003-20200820 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project b587ca93be114d07ec3bf654add97d7872325281)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
>> drivers/pci/pci-acpi.c:1236:8: error: no member named 'max_snoop_latency' in 'struct pci_dev'
dev->max_snoop_latency = (u16)elements[1].integer.value |
~~~ ^
>> drivers/pci/pci-acpi.c:1238:8: error: no member named 'max_nosnoop_latency' in 'struct pci_dev'
dev->max_nosnoop_latency = (u16)elements[3].integer.value |
~~~ ^
2 errors generated.
# https://github.com/0day-ci/linux/commit/2aef8c301151afccc59ac8c0ad321f4e0f77d453
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Puranjay-Mohan/PCI-Add-support-for-LTR/20200822-031519
git checkout 2aef8c301151afccc59ac8c0ad321f4e0f77d453
vim +1236 drivers/pci/pci-acpi.c
1215
1216 /* pci_acpi_evaluate_ltr_latency
1217 *
1218 * @dev - the pci_dev to evaluate and save latencies
1219 */
1220 void pci_acpi_evaluate_ltr_latency(struct pci_dev *dev)
1221 {
1222 union acpi_object *obj, *elements;
1223 struct acpi_device *handle;
1224
1225 handle = ACPI_HANDLE(&dev->dev);
1226 if (!handle)
1227 return;
1228
1229 obj = acpi_evaluate_dsm(handle, &pci_acpi_dsm_guid, 0x2,
1230 DSM_PCI_LTR_MAX_LATENCY, NULL);
1231 if (!obj)
1232 return;
1233
1234 if (obj->type == ACPI_TYPE_PACKAGE && obj->package.count == 4) {
1235 elements = obj->package.elements;
> 1236 dev->max_snoop_latency = (u16)elements[1].integer.value |
1237 ((u16)elements[0].integer.value << PCI_LTR_SCALE_SHIFT);
> 1238 dev->max_nosnoop_latency = (u16)elements[3].integer.value |
1239 ((u16)elements[2].integer.value << PCI_LTR_SCALE_SHIFT);
1240 }
1241 ACPI_FREE(obj);
1242 }
1243
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32237 bytes --]
[-- Attachment #3: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-21 22:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-21 19:13 [Linux-kernel-mentees] [PATCH] PCI: Add support for LTR Puranjay Mohan
2020-08-21 21:56 ` kernel test robot
2020-08-21 22:32 ` kernel test robot
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).