diff mbox series

[v3,1/3] ACPI/APEI: Add hest_parse_pcie_aer()

Message ID 20240718062405.30571-2-LeoLiu-oc@zhaoxin.com (mailing list archive)
State New
Delegated to: Bjorn Helgaas
Headers show
Series Parse the HEST PCIe AER and set to relevant registers | expand

Commit Message

LeoLiu-oc July 18, 2024, 6:24 a.m. UTC
From: LeoLiuoc <LeoLiu-oc@zhaoxin.com>

The purpose of the function apei_hest_parse_aer() is used to parse and
extract register value from HEST PCIe AER structures. This applies to
all hardware platforms that has a PCI Express AER structure in HEST.

Signed-off-by: LeoLiuoc <LeoLiu-oc@zhaoxin.com>
---
 drivers/acpi/apei/hest.c | 66 ++++++++++++++++++++++++++++++++++++++--
 include/acpi/apei.h      | 17 +++++++++++
 2 files changed, 81 insertions(+), 2 deletions(-)

Comments

kernel test robot July 18, 2024, 5:10 p.m. UTC | #1
Hi LeoLiu-oc,

kernel test robot noticed the following build warnings:

[auto build test WARNING on pci/for-linus]
[also build test WARNING on rafael-pm/linux-next rafael-pm/bleeding-edge linus/master v6.10 next-20240718]
[cannot apply to pci/next]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/LeoLiu-oc/ACPI-APEI-Add-hest_parse_pcie_aer/20240718-144218
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git for-linus
patch link:    https://lore.kernel.org/r/20240718062405.30571-2-LeoLiu-oc%40zhaoxin.com
patch subject: [PATCH v3 1/3] ACPI/APEI: Add hest_parse_pcie_aer()
config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20240719/202407190015.eutiIYQp-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240719/202407190015.eutiIYQp-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202407190015.eutiIYQp-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/acpi/apei/hest.c:157:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
     157 |         case ACPI_HEST_TYPE_AER_ENDPOINT:
         |         ^
   drivers/acpi/apei/hest.c:157:2: note: insert '__attribute__((fallthrough));' to silence this warning
     157 |         case ACPI_HEST_TYPE_AER_ENDPOINT:
         |         ^
         |         __attribute__((fallthrough)); 
   drivers/acpi/apei/hest.c:157:2: note: insert 'break;' to avoid fall-through
     157 |         case ACPI_HEST_TYPE_AER_ENDPOINT:
         |         ^
         |         break; 
   drivers/acpi/apei/hest.c:160:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
     160 |         case ACPI_HEST_TYPE_AER_BRIDGE:
         |         ^
   drivers/acpi/apei/hest.c:160:2: note: insert '__attribute__((fallthrough));' to silence this warning
     160 |         case ACPI_HEST_TYPE_AER_BRIDGE:
         |         ^
         |         __attribute__((fallthrough)); 
   drivers/acpi/apei/hest.c:160:2: note: insert 'break;' to avoid fall-through
     160 |         case ACPI_HEST_TYPE_AER_BRIDGE:
         |         ^
         |         break; 
   drivers/acpi/apei/hest.c:163:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
     163 |         default:
         |         ^
   drivers/acpi/apei/hest.c:163:2: note: insert '__attribute__((fallthrough));' to silence this warning
     163 |         default:
         |         ^
         |         __attribute__((fallthrough)); 
   drivers/acpi/apei/hest.c:163:2: note: insert 'break;' to avoid fall-through
     163 |         default:
         |         ^
         |         break; 
   3 warnings generated.


vim +157 drivers/acpi/apei/hest.c

   144	
   145	static bool hest_source_is_pcie_aer(struct acpi_hest_header *hest_hdr, struct pci_dev *dev)
   146	{
   147		u16 hest_type = hest_hdr->type;
   148		u8 pcie_type = pci_pcie_type(dev);
   149		struct acpi_hest_aer_common *common;
   150	
   151		common = (struct acpi_hest_aer_common *)(hest_hdr + 1);
   152	
   153		switch (hest_type) {
   154		case ACPI_HEST_TYPE_AER_ROOT_PORT:
   155			if (pcie_type != PCI_EXP_TYPE_ROOT_PORT)
   156				return false;
 > 157		case ACPI_HEST_TYPE_AER_ENDPOINT:
   158			if (pcie_type != PCI_EXP_TYPE_ENDPOINT)
   159				return false;
   160		case ACPI_HEST_TYPE_AER_BRIDGE:
   161			if (pcie_type != PCI_EXP_TYPE_PCI_BRIDGE && pcie_type != PCI_EXP_TYPE_PCIE_BRIDGE)
   162				return false;
   163		default:
   164			return false;
   165		}
   166	
   167		if (common->flags & ACPI_HEST_GLOBAL)
   168			return true;
   169	
   170		if (hest_match_pci_devfn(common, dev))
   171			return true;
   172	
   173		return false;
   174	}
   175
kernel test robot July 18, 2024, 5:53 p.m. UTC | #2
Hi LeoLiu-oc,

kernel test robot noticed the following build warnings:

[auto build test WARNING on pci/for-linus]
[also build test WARNING on rafael-pm/linux-next rafael-pm/bleeding-edge linus/master v6.10 next-20240718]
[cannot apply to pci/next]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/LeoLiu-oc/ACPI-APEI-Add-hest_parse_pcie_aer/20240718-144218
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git for-linus
patch link:    https://lore.kernel.org/r/20240718062405.30571-2-LeoLiu-oc%40zhaoxin.com
patch subject: [PATCH v3 1/3] ACPI/APEI: Add hest_parse_pcie_aer()
config: x86_64-randconfig-161-20240718 (https://download.01.org/0day-ci/archive/20240719/202407190133.KRXYQI5m-lkp@intel.com/config)
compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240719/202407190133.KRXYQI5m-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202407190133.KRXYQI5m-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/acpi/apei/hest.c: In function 'hest_source_is_pcie_aer':
>> drivers/acpi/apei/hest.c:155:20: warning: this statement may fall through [-Wimplicit-fallthrough=]
     155 |                 if (pcie_type != PCI_EXP_TYPE_ROOT_PORT)
         |                    ^
   drivers/acpi/apei/hest.c:157:9: note: here
     157 |         case ACPI_HEST_TYPE_AER_ENDPOINT:
         |         ^~~~
   drivers/acpi/apei/hest.c:158:20: warning: this statement may fall through [-Wimplicit-fallthrough=]
     158 |                 if (pcie_type != PCI_EXP_TYPE_ENDPOINT)
         |                    ^
   drivers/acpi/apei/hest.c:160:9: note: here
     160 |         case ACPI_HEST_TYPE_AER_BRIDGE:
         |         ^~~~
   drivers/acpi/apei/hest.c:161:20: warning: this statement may fall through [-Wimplicit-fallthrough=]
     161 |                 if (pcie_type != PCI_EXP_TYPE_PCI_BRIDGE && pcie_type != PCI_EXP_TYPE_PCIE_BRIDGE)
         |                    ^
   drivers/acpi/apei/hest.c:163:9: note: here
     163 |         default:
         |         ^~~~~~~


vim +155 drivers/acpi/apei/hest.c

   144	
   145	static bool hest_source_is_pcie_aer(struct acpi_hest_header *hest_hdr, struct pci_dev *dev)
   146	{
   147		u16 hest_type = hest_hdr->type;
   148		u8 pcie_type = pci_pcie_type(dev);
   149		struct acpi_hest_aer_common *common;
   150	
   151		common = (struct acpi_hest_aer_common *)(hest_hdr + 1);
   152	
   153		switch (hest_type) {
   154		case ACPI_HEST_TYPE_AER_ROOT_PORT:
 > 155			if (pcie_type != PCI_EXP_TYPE_ROOT_PORT)
   156				return false;
   157		case ACPI_HEST_TYPE_AER_ENDPOINT:
   158			if (pcie_type != PCI_EXP_TYPE_ENDPOINT)
   159				return false;
   160		case ACPI_HEST_TYPE_AER_BRIDGE:
   161			if (pcie_type != PCI_EXP_TYPE_PCI_BRIDGE && pcie_type != PCI_EXP_TYPE_PCIE_BRIDGE)
   162				return false;
   163		default:
   164			return false;
   165		}
   166	
   167		if (common->flags & ACPI_HEST_GLOBAL)
   168			return true;
   169	
   170		if (hest_match_pci_devfn(common, dev))
   171			return true;
   172	
   173		return false;
   174	}
   175
diff mbox series

Patch

diff --git a/drivers/acpi/apei/hest.c b/drivers/acpi/apei/hest.c
index 20d757687e3d..ecfb89b7d19f 100644
--- a/drivers/acpi/apei/hest.c
+++ b/drivers/acpi/apei/hest.c
@@ -22,6 +22,7 @@ 
 #include <linux/kdebug.h>
 #include <linux/highmem.h>
 #include <linux/io.h>
+#include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <acpi/apei.h>
 #include <acpi/ghes.h>
@@ -132,9 +133,70 @@  static bool is_ghes_assist_struct(struct acpi_hest_header *hest_hdr)
 	return false;
 }
 
-typedef int (*apei_hest_func_t)(struct acpi_hest_header *hest_hdr, void *data);
+#ifdef CONFIG_ACPI_APEI
+static bool hest_match_pci_devfn(struct acpi_hest_aer_common *p, struct pci_dev *dev)
+{
+	return ACPI_HEST_SEGMENT(p->bus) == pci_domain_nr(dev->bus) &&
+	       ACPI_HEST_BUS(p->bus) == dev->bus->number &&
+	       p->device == PCI_SLOT(dev->devfn) &&
+	       p->function == PCI_FUNC(dev->devfn);
+}
+
+static bool hest_source_is_pcie_aer(struct acpi_hest_header *hest_hdr, struct pci_dev *dev)
+{
+	u16 hest_type = hest_hdr->type;
+	u8 pcie_type = pci_pcie_type(dev);
+	struct acpi_hest_aer_common *common;
+
+	common = (struct acpi_hest_aer_common *)(hest_hdr + 1);
+
+	switch (hest_type) {
+	case ACPI_HEST_TYPE_AER_ROOT_PORT:
+		if (pcie_type != PCI_EXP_TYPE_ROOT_PORT)
+			return false;
+	case ACPI_HEST_TYPE_AER_ENDPOINT:
+		if (pcie_type != PCI_EXP_TYPE_ENDPOINT)
+			return false;
+	case ACPI_HEST_TYPE_AER_BRIDGE:
+		if (pcie_type != PCI_EXP_TYPE_PCI_BRIDGE && pcie_type != PCI_EXP_TYPE_PCIE_BRIDGE)
+			return false;
+	default:
+		return false;
+	}
+
+	if (common->flags & ACPI_HEST_GLOBAL)
+		return true;
+
+	if (hest_match_pci_devfn(common, dev))
+		return true;
+
+	return false;
+}
+
+int hest_parse_pcie_aer(struct acpi_hest_header *hest_hdr, void *data)
+{
+	struct hest_parse_aer_info *info = data;
+
+	if (!hest_source_is_pcie_aer(hest_hdr, info->pci_dev))
+		return 0;
+
+	switch (hest_hdr->type) {
+	case ACPI_HEST_TYPE_AER_ROOT_PORT:
+		info->hest_aer_root_port = (struct acpi_hest_aer_root *)hest_hdr;
+		return 1;
+	case ACPI_HEST_TYPE_AER_ENDPOINT:
+		info->hest_aer_endpoint = (struct acpi_hest_aer *)hest_hdr;
+		return 1;
+	case ACPI_HEST_TYPE_AER_BRIDGE:
+		info->hest_aer_bridge = (struct acpi_hest_aer_bridge *)hest_hdr;
+		return 1;
+	default:
+		return 0;
+	}
+}
+#endif
 
-static int apei_hest_parse(apei_hest_func_t func, void *data)
+int apei_hest_parse(apei_hest_func_t func, void *data)
 {
 	struct acpi_hest_header *hest_hdr;
 	int i, rc, len;
diff --git a/include/acpi/apei.h b/include/acpi/apei.h
index dc60f7db5524..82d3cdf53e22 100644
--- a/include/acpi/apei.h
+++ b/include/acpi/apei.h
@@ -23,6 +23,15 @@  enum hest_status {
 	HEST_NOT_FOUND,
 };
 
+#ifdef CONFIG_ACPI_APEI
+struct hest_parse_aer_info {
+	struct pci_dev *pci_dev;
+	struct acpi_hest_aer *hest_aer_endpoint;
+	struct acpi_hest_aer_root *hest_aer_root_port;
+	struct acpi_hest_aer_bridge *hest_aer_bridge;
+};
+#endif
+
 extern int hest_disable;
 extern int erst_disable;
 #ifdef CONFIG_ACPI_APEI_GHES
@@ -33,10 +42,18 @@  void __init acpi_ghes_init(void);
 static inline void acpi_ghes_init(void) { }
 #endif
 
+typedef int (*apei_hest_func_t)(struct acpi_hest_header *hest_hdr, void *data);
+int apei_hest_parse(apei_hest_func_t func, void *data);
+
 #ifdef CONFIG_ACPI_APEI
 void __init acpi_hest_init(void);
+int hest_parse_pcie_aer(struct acpi_hest_header *hest_hdr, void *data);
 #else
 static inline void acpi_hest_init(void) { }
+static inline int hest_parse_pcie_aer(struct acpi_hest_header *hest_hdr, void *data)
+{
+	return 0;
+}
 #endif
 
 int erst_write(const struct cper_record_header *record);