PCI: Move TLP Log handling to its own file
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 14 Jan 2025 17:08:34 +0000 (19:08 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 14 Jan 2025 23:38:18 +0000 (17:38 -0600)
TLP Log is a PCIe feature and is processed only by AER and DPC.
Configwise, DPC depends AER being enabled. In lack of better place, the TLP
Log handling code was initially placed into pci.c but it can be easily
placed in a separate file.

Move TLP Log handling code to its own file under pcie/ subdirectory and
include it only when AER is enabled.

Link: https://lore.kernel.org/r/20250114170840.1633-3-ilpo.jarvinen@linux.intel.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Yazen Ghannam <yazen.ghannam@amd.com>
drivers/pci/pci.c
drivers/pci/pci.h
drivers/pci/pcie/Makefile
drivers/pci/pcie/tlp.c [new file with mode: 0644]

index e0fdc9d10f913615e97eb7c811c3da1439a1e9d7..02cd4c7eb80b3a62308d98626e8ae54c4eb759bb 100644 (file)
@@ -1099,33 +1099,6 @@ static void pci_enable_acs(struct pci_dev *dev)
        pci_write_config_word(dev, pos + PCI_ACS_CTRL, caps.ctrl);
 }
 
-/**
- * pcie_read_tlp_log - read TLP Header Log
- * @dev: PCIe device
- * @where: PCI Config offset of TLP Header Log
- * @tlp_log: TLP Log structure to fill
- *
- * Fill @tlp_log from TLP Header Log registers, e.g., AER or DPC.
- *
- * Return: 0 on success and filled TLP Log structure, <0 on error.
- */
-int pcie_read_tlp_log(struct pci_dev *dev, int where,
-                     struct pcie_tlp_log *tlp_log)
-{
-       int i, ret;
-
-       memset(tlp_log, 0, sizeof(*tlp_log));
-
-       for (i = 0; i < 4; i++) {
-               ret = pci_read_config_dword(dev, where + i * 4,
-                                           &tlp_log->dw[i]);
-               if (ret)
-                       return pcibios_err_to_errno(ret);
-       }
-
-       return 0;
-}
-
 /**
  * pci_restore_bars - restore a device's BAR values (e.g. after wake-up)
  * @dev: PCI device to have its BARs restored
index 8a60fc9e77869d5ffefefb2d094274a6aa4a3784..55fcf3bac4f7e4d4f210d24d7d42e4b891a0f49d 100644 (file)
@@ -549,9 +549,9 @@ struct aer_err_info {
 
 int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info);
 void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
-#endif /* CONFIG_PCIEAER */
 
 int pcie_read_tlp_log(struct pci_dev *dev, int where, struct pcie_tlp_log *log);
+#endif /* CONFIG_PCIEAER */
 
 #ifdef CONFIG_PCIEPORTBUS
 /* Cached RCEC Endpoint Association */
index 53ccab62314d972a6dbc5ce9a33d39b9e2dc86eb..173829aa02e60624262b5f276c1fc11d2344c335 100644 (file)
@@ -7,7 +7,7 @@ pcieportdrv-y                   := portdrv.o rcec.o
 obj-$(CONFIG_PCIEPORTBUS)      += pcieportdrv.o bwctrl.o
 
 obj-y                          += aspm.o
-obj-$(CONFIG_PCIEAER)          += aer.o err.o
+obj-$(CONFIG_PCIEAER)          += aer.o err.o tlp.o
 obj-$(CONFIG_PCIEAER_INJECT)   += aer_inject.o
 obj-$(CONFIG_PCIE_PME)         += pme.o
 obj-$(CONFIG_PCIE_DPC)         += dpc.o
diff --git a/drivers/pci/pcie/tlp.c b/drivers/pci/pcie/tlp.c
new file mode 100644 (file)
index 0000000..3f053cc
--- /dev/null
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PCIe TLP Log handling
+ *
+ * Copyright (C) 2024 Intel Corporation
+ */
+
+#include <linux/aer.h>
+#include <linux/pci.h>
+#include <linux/string.h>
+
+#include "../pci.h"
+
+/**
+ * pcie_read_tlp_log - read TLP Header Log
+ * @dev: PCIe device
+ * @where: PCI Config offset of TLP Header Log
+ * @tlp_log: TLP Log structure to fill
+ *
+ * Fill @tlp_log from TLP Header Log registers, e.g., AER or DPC.
+ *
+ * Return: 0 on success and filled TLP Log structure, <0 on error.
+ */
+int pcie_read_tlp_log(struct pci_dev *dev, int where,
+                     struct pcie_tlp_log *tlp_log)
+{
+       int i, ret;
+
+       memset(tlp_log, 0, sizeof(*tlp_log));
+
+       for (i = 0; i < 4; i++) {
+               ret = pci_read_config_dword(dev, where + i * 4,
+                                           &tlp_log->dw[i]);
+               if (ret)
+                       return pcibios_err_to_errno(ret);
+       }
+
+       return 0;
+}