Skip to contentSkip to conversation

PCI: hip: Add handling of HiSilicon HIP PCIe controller errors

PATCH Superseded Shiju Jose 3 participants 9 messages Jun 15, 2020 – Jun 17, 2020

Subsystems (3)

v9 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

Shiju Jose

author
#0 lore raw

PATCH v9 2/2 PCI: hip: Add handling of HiSilicon HIP PCIe controller errors

From: Yicong Yang <[email protected]>

The HiSilicon HIP PCIe controller is capable of handling errors on root port and perform port reset separately at each root port.

Add error handling driver for HIP PCIe controller to log and report recoverable errors. Perform root port reset and restore link status after the recovery.

Following are some of the PCIe controller's recoverable errors
1. completion transmission timeout error.
2. CRS retry counter over the threshold error.
3. ECC 2 bit errors
4. AXI bresponse/rresponse errors etc.

The driver placed in the drivers/pci/controller/ because the HIP PCIe controller does not use DWC ip.

--

drivers/pci/controller/Kconfig           |   8 +
drivers/pci/controller/Makefile          |   1 +
drivers/pci/controller/pcie-hisi-error.c | 336 +++++++++++++++++++++++++++++++
3 files changed, 345 insertions(+)
create mode 100644 drivers/pci/controller/pcie-hisi-error.c
---
 drivers/pci/controller/Kconfig           |   8 +
 drivers/pci/controller/Makefile          |   1 +
 drivers/pci/controller/pcie-hisi-error.c | 305 +++++++++++++++++++++++
 3 files changed, 314 insertions(+)
 create mode 100644 drivers/pci/controller/pcie-hisi-error.c
drivers/pci/controller/Kconfig +8 -0
index 91bfdb784829..7ba4b94f8604 100644
@@ -258,6 +258,14 @@ config PCI_HYPERV_INTERFACE
 	  The Hyper-V PCI Interface is a helper driver allows other drivers to
 	  have a common interface with the Hyper-V PCI frontend driver.
 
+config PCIE_HISI_ERR
+	depends on ARM64 || COMPILE_TEST
+	depends on ACPI
+	bool "HiSilicon HIP PCIe controller error handling driver"
+	help
+	  Say Y here if you want error handling support
+	  for the PCIe controller's errors on HiSilicon HIP SoCs
+
 source "drivers/pci/controller/dwc/Kconfig"
 source "drivers/pci/controller/mobiveil/Kconfig"
 source "drivers/pci/controller/cadence/Kconfig"
drivers/pci/controller/Makefile +1 -0
index 158c59771824..ab3a528bf988 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_PCIE_MEDIATEK) += pcie-mediatek.o
 obj-$(CONFIG_PCIE_TANGO_SMP8759) += pcie-tango.o
 obj-$(CONFIG_VMD) += vmd.o
 obj-$(CONFIG_PCIE_BRCMSTB) += pcie-brcmstb.o
+obj-$(CONFIG_PCIE_HISI_ERR) += pcie-hisi-error.o
 # pcie-hisi.o quirks are needed even without CONFIG_PCIE_DW
 obj-y				+= dwc/
 obj-y				+= mobiveil/
drivers/pci/controller/pcie-hisi-error.c new file +305 -0

305 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw
Quoted 17 lines · Shiju Jose

From: Yicong Yang <[email protected]>

The HiSilicon HIP PCIe controller is capable of handling errors on root port and perform port reset separately at each root port.

Add error handling driver for HIP PCIe controller to log and report recoverable errors. Perform root port reset and restore link status after the recovery.

Following are some of the PCIe controller's recoverable errors
1. completion transmission timeout error.
2. CRS retry counter over the threshold error.
3. ECC 2 bit errors
4. AXI bresponse/rresponse errors etc.

The driver placed in the drivers/pci/controller/ because the HIP PCIe controller does not use DWC ip.

...

drivers/pci/controller/pcie-hisi-error.c line 10

Quoted 2 lines
drivers/pci/controller/pcie-hisi-error.c new file +2 -0
+#include <linux/acpi.h>
+#include <acpi/ghes.h>

bits.h ?

Quoted 5 lines
drivers/pci/controller/pcie-hisi-error.c new file +5 -0
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/platform_device.h>
+#include <linux/kfifo.h>
+#include <linux/spinlock.h>

...

drivers/pci/controller/pcie-hisi-error.c line 43

Quoted 2 lines
drivers/pci/controller/pcie-hisi-error.c new file +2 -0
+static guid_t hisi_pcie_sec_type = GUID_INIT(0xB2889FC9, 0xE7D7, 0x4F9D,
+			0xA8, 0x67, 0xAF, 0x42, 0xE9, 0x8B, 0xE7, 0x72);

Can we have it in more common pattern, i.e.

static guid_t hisi_pcie_sec_type =

	GUID_INIT(0xB2889FC9, 0xE7D7, 0x4F9D,
		  0xA8, 0x67, 0xAF, 0x42, 0xE9, 0x8B, 0xE7, 0x72);

?

...

Quoted 1 line

+#define HISI_PCIE_CORE_PORT_ID(v) (((v) % 8) << 1)

% -> & ?

...

drivers/pci/controller/pcie-hisi-error.c line 66

Quoted 3 lines
drivers/pci/controller/pcie-hisi-error.c new file +3 -0
+struct hisi_pcie_error_private {
+	struct notifier_block	nb;
+	struct platform_device	*pdev;

Do you really need platform device? Isn't struct device * enough?

Quoted 1 line

+};

...

drivers/pci/controller/pcie-hisi-error.c line 77

Quoted 9 lines
drivers/pci/controller/pcie-hisi-error.c new file +9 -0
+static char *hisi_pcie_sub_module_name(u8 id)
+{
+	switch (id) {
+	case HISI_PCIE_SUB_MODULE_ID_AP: return "AP Layer";
+	case HISI_PCIE_SUB_MODULE_ID_TL: return "TL Layer";
+	case HISI_PCIE_SUB_MODULE_ID_MAC: return "MAC Layer";
+	case HISI_PCIE_SUB_MODULE_ID_DL: return "DL Layer";
+	case HISI_PCIE_SUB_MODULE_ID_SDI: return "SDI Layer";
+	}

match_string() ?

drivers/pci/controller/pcie-hisi-error.c line 89

Quoted 12 lines
drivers/pci/controller/pcie-hisi-error.c new file +11 -0
+	return "unknown";
 
+}
+
+static char *hisi_pcie_error_severity(u8 err_sev)
+{
+	switch (err_sev) {
+	case HISI_ERR_SEV_RECOVERABLE: return "recoverable";
+	case HISI_ERR_SEV_FATAL: return "fatal";
+	case HISI_ERR_SEV_CORRECTED: return "corrected";
+	case HISI_ERR_SEV_NONE: return "none";
+	}

Ditto?

Quoted 2 lines
(quoted diff) +2 -0
+	return "unknown";
+}

...

drivers/pci/controller/pcie-hisi-error.c line 153

Quoted 5 lines
drivers/pci/controller/pcie-hisi-error.c new file +4 -0
+	pdev = pci_get_domain_bus_and_slot(domain, busnr, devfn);
+	if (!pdev) {
 
+		dev_info(device, "Fail to get root port %04x:%02x:%02x.%d device\n",
+			 domain, busnr, PCI_SLOT(devfn), PCI_FUNC(devfn));

pci_info() ?

Quoted 2 lines
(quoted diff) +2 -0
+		return -ENODEV;
+	}

...

drivers/pci/controller/pcie-hisi-error.c line 170

Quoted 8 lines
drivers/pci/controller/pcie-hisi-error.c new file +8 -0
+	/*
+	 * The initialization time of subordinate devices after
+	 * hot reset is no more than 1s, which is required by
+	 * the PCI spec v5.0 sec 6.6.1. The time will shorten
+	 * if Readiness Notifications mechanisms are used. But
+	 * wait 1s here to adapt any conditions.
+	 */
+	ssleep(1UL);

It's a huge time out... Can we reduce it somehow?

...

drivers/pci/controller/pcie-hisi-error.c line 215

Quoted 3 lines
drivers/pci/controller/pcie-hisi-error.c new file +3 -0
+	for (i = 0; i < HISI_PCIE_ERR_MISC_REGS; i++) {
+		if (edata->val_bits &
+				BIT_ULL(HISI_PCIE_LOCAL_VALID_ERR_MISC + i))

for_each_set_bit() ?

drivers/pci/controller/pcie-hisi-error.c line 221

Quoted 7 lines
drivers/pci/controller/pcie-hisi-error.c new file +6 -0
+			dev_info(dev,
+				 "ERR_MISC_%d = 0x%x\n", i, edata->err_misc[i]);
+	}
 
+
+	/* Recovery for the PCIe controller errors */
+	if (edata->err_severity == HISI_ERR_SEV_RECOVERABLE) {

Perhaps negative conditional?

drivers/pci/controller/pcie-hisi-error.c line 227

Quoted 7 lines
drivers/pci/controller/pcie-hisi-error.c new file +6 -0
+		/* try reset PCI port for the error recovery */
+		rc = hisi_pcie_port_do_recovery(pdev, edata->socket_id,
+			HISI_PCIE_PORT_ID(edata->core_id, edata->port_id));
+		if (rc) {
+			dev_info(dev, "fail to do hisi pcie port reset\n");
 
+			return;

redundant.

Quoted 2 lines
(quoted diff) +2 -0
+		}
+	}

...

drivers/pci/controller/pcie-hisi-error.c line 237

Quoted 2 lines
drivers/pci/controller/pcie-hisi-error.c new file +2 -0
+	const struct hisi_pcie_error_data *error_data =
+				acpi_hest_get_payload(gdata);

One line is better to read.

drivers/pci/controller/pcie-hisi-error.c line 251

Quoted 3 lines
drivers/pci/controller/pcie-hisi-error.c new file +2 -0
+	struct platform_device *pdev = priv->pdev;
 
+	hisi_pcie_handle_error(pdev, error_data);

And how exactly _platform_ device pointer is being used?

...

drivers/pci/controller/pcie-hisi-error.c line 270

Quoted 2 lines
drivers/pci/controller/pcie-hisi-error.c new file +2 -0
+		dev_err(&pdev->dev, "%s : ghes_register_event_notifier fail\n",
+			__func__);

Make error message more descriptive that __func__ will not be needed.

...

drivers/pci/controller/pcie-hisi-error.c line 284

Quoted 1 line
drivers/pci/controller/pcie-hisi-error.c new file +1 -0
+	kfree(priv);

Double free?

...

drivers/pci/controller/pcie-hisi-error.c line 290

Quoted 2 lines
drivers/pci/controller/pcie-hisi-error.c new file +2 -0
+static const struct acpi_device_id hisi_pcie_acpi_match[] = {
+	{ "HISI0361", 0 },

', 0' part is not necessary to have.

Quoted 2 lines
(quoted diff) +2 -0
+	{ }
+};
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#2 lore raw

Hi Andy,

Thanks for the reviewing the patch.

Quoted 33 lines

-----Original Message-----
From: Andy Shevchenko [mailto:[email protected]]
Sent: 15 June 2020 13:01
To: Shiju Jose <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wangkefeng (OS Kernel Lab) <[email protected]>; [email protected]; yangyicong <[email protected]>; Jonathan Cameron <[email protected]>; tanxiaofei <[email protected]>
Subject: Re: [PATCH v9 2/2] PCI: hip: Add handling of HiSilicon HIP PCIe controller errors

Quoted 9 lines · Shiju Jose

From: Yicong Yang <[email protected]>

The HiSilicon HIP PCIe controller is capable of handling errors on root port and perform port reset separately at each root port.

Add error handling driver for HIP PCIe controller to log and report recoverable errors. Perform root port reset and restore link status after the recovery.

Quoted 8 lines

Following are some of the PCIe controller's recoverable errors 1. completion transmission timeout error.
2. CRS retry counter over the threshold error.
3. ECC 2 bit errors
4. AXI bresponse/rresponse errors etc.

The driver placed in the drivers/pci/controller/ because the HIP PCIe controller does not use DWC ip.

Quoted 6 lines

...

drivers/pci/controller/pcie-hisi-error.c line 10

Quoted 2 lines
drivers/pci/controller/pcie-hisi-error.c new file +2 -0
+#include <linux/acpi.h>
+#include <acpi/ghes.h>

bits.h ?

Ok. I think bits.h was already included through some other .h files.

Quoted 10 lines
Quoted 6 lines
drivers/pci/controller/pcie-hisi-error.c new file +5 -0
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/platform_device.h>
+#include <linux/kfifo.h>
+#include <linux/spinlock.h>

...

Quoted 1 line

+static guid_t hisi_pcie_sec_type = GUID_INIT(0xB2889FC9, 0xE7D7,

Quoted 8 lines

0x4F9D,

drivers/pci/controller/pcie-hisi-error.c line 43

Quoted 1 line
drivers/pci/controller/pcie-hisi-error.c new file +1 -0
+			0xA8, 0x67, 0xAF, 0x42, 0xE9, 0x8B, 0xE7, 0x72);

Can we have it in more common pattern, i.e.

static guid_t hisi_pcie_sec_type =

	GUID_INIT(0xB2889FC9, 0xE7D7, 0x4F9D,
		  0xA8, 0x67, 0xAF, 0x42, 0xE9, 0x8B, 0xE7, 0x72); ?

Ok. Will change it.

Quoted 6 lines

...

Quoted 1 line

+#define HISI_PCIE_CORE_PORT_ID(v) (((v) % 8) << 1)

% -> & ?

(((v) % 8) << 1) is correct. We can make bit operation instead.

Quoted 8 lines

...

drivers/pci/controller/pcie-hisi-error.c line 66

Quoted 3 lines
drivers/pci/controller/pcie-hisi-error.c new file +3 -0
+struct hisi_pcie_error_private {
+	struct notifier_block	nb;
+	struct platform_device	*pdev;

Do you really need platform device? Isn't struct device * enough?

We need platform device as the error recovery device is a platform device, which provides us the "RST" reset method.

Quoted 5 lines
Quoted 2 lines

+};

...

Quoted 10 lines

drivers/pci/controller/pcie-hisi-error.c line 77

Quoted 8 lines
drivers/pci/controller/pcie-hisi-error.c new file +8 -0
+static char *hisi_pcie_sub_module_name(u8 id) {
+	switch (id) {
+	case HISI_PCIE_SUB_MODULE_ID_AP: return "AP Layer";
+	case HISI_PCIE_SUB_MODULE_ID_TL: return "TL Layer";
+	case HISI_PCIE_SUB_MODULE_ID_MAC: return "MAC Layer";
+	case HISI_PCIE_SUB_MODULE_ID_DL: return "DL Layer";
+	case HISI_PCIE_SUB_MODULE_ID_SDI: return "SDI Layer";
+	}

match_string() ?

match_string() does not work here because we need sub module id -> string conversion.

Quoted 14 lines

drivers/pci/controller/pcie-hisi-error.c line 89

Quoted 12 lines
drivers/pci/controller/pcie-hisi-error.c new file +10 -0
+	return "unknown";
 
+}
+
+static char *hisi_pcie_error_severity(u8 err_sev) {
+	switch (err_sev) {
+	case HISI_ERR_SEV_RECOVERABLE: return "recoverable";
+	case HISI_ERR_SEV_FATAL: return "fatal";
+	case HISI_ERR_SEV_CORRECTED: return "corrected";
+	case HISI_ERR_SEV_NONE: return "none";
+	}

Ditto?

Same as above.

Quoted 6 lines
Quoted 3 lines
(quoted diff) +2 -0
+	return "unknown";
+}

...

Quoted 8 lines

drivers/pci/controller/pcie-hisi-error.c

Quoted 4 lines
drivers/pci/controller/pcie-hisi-error.c new file +3 -0
+	pdev = pci_get_domain_bus_and_slot(domain, busnr, devfn);
+	if (!pdev) {
 
+		dev_info(device, "Fail to get root port %04x:%02x:%02x.%d

device\n",

drivers/pci/controller/pcie-hisi-error.c line 153

Quoted 1 line
drivers/pci/controller/pcie-hisi-error.c new file +1 -0
+			 domain, busnr, PCI_SLOT(devfn), PCI_FUNC(devfn));

pci_info() ?

It's wrong to use pci_info() here, as in the branch we haven't get a pci device and also we're printing info's of the error handler device driver, not a pci device driver.

Quoted 6 lines
Quoted 3 lines
(quoted diff) +2 -0
+		return -ENODEV;
+	}

...

Quoted 10 lines

drivers/pci/controller/pcie-hisi-error.c line 170

Quoted 8 lines
drivers/pci/controller/pcie-hisi-error.c new file +8 -0
+	/*
+	 * The initialization time of subordinate devices after
+	 * hot reset is no more than 1s, which is required by
+	 * the PCI spec v5.0 sec 6.6.1. The time will shorten
+	 * if Readiness Notifications mechanisms are used. But
+	 * wait 1s here to adapt any conditions.
+	 */
+	ssleep(1UL);

It's a huge time out... Can we reduce it somehow?

Less time may leads downstream traffic not recovered, so it's better of follow the spec, which is also done by the PCI driver.

Quoted 9 lines

...

drivers/pci/controller/pcie-hisi-error.c

Quoted 3 lines
drivers/pci/controller/pcie-hisi-error.c new file +3 -0
+	for (i = 0; i < HISI_PCIE_ERR_MISC_REGS; i++) {
+		if (edata->val_bits &
+				BIT_ULL(HISI_PCIE_LOCAL_VALID_ERR_MISC

+ i))

for_each_set_bit() ?

Can't use for_each_set_bit() here because edata->val_bits contains valid bits for other fields of the error data as well, those need to printed separately.

Quoted 11 lines

drivers/pci/controller/pcie-hisi-error.c line 221

Quoted 9 lines
(quoted diff) +2 -0
+			dev_info(dev,
+				 "ERR_MISC_%d = 0x%x\n", i, edata-

err_misc[i]);

drivers/pci/controller/pcie-hisi-error.c new file +4 -0
+	}
 
+
+	/* Recovery for the PCIe controller errors */
+	if (edata->err_severity == HISI_ERR_SEV_RECOVERABLE) {

Perhaps negative conditional?

Ok. Will change it.

Quoted 10 lines

drivers/pci/controller/pcie-hisi-error.c line 227

Quoted 8 lines
drivers/pci/controller/pcie-hisi-error.c new file +6 -0
+		/* try reset PCI port for the error recovery */
+		rc = hisi_pcie_port_do_recovery(pdev, edata->socket_id,
+			HISI_PCIE_PORT_ID(edata->core_id, edata->port_id));
+		if (rc) {
+			dev_info(dev, "fail to do hisi pcie port reset\n");
 
+			return;

redundant.

Ok. Will remove it.

Quoted 10 lines
Quoted 3 lines
(quoted diff) +2 -0
+		}
+	}

...

drivers/pci/controller/pcie-hisi-error.c line 237

Quoted 2 lines
drivers/pci/controller/pcie-hisi-error.c new file +2 -0
+	const struct hisi_pcie_error_data *error_data =
+				acpi_hest_get_payload(gdata);

One line is better to read.

Checkpatch warning, the length of line will exceed 80 characters.

Quoted 7 lines

drivers/pci/controller/pcie-hisi-error.c line 251

Quoted 4 lines
drivers/pci/controller/pcie-hisi-error.c new file +2 -0
+	struct platform_device *pdev = priv->pdev;
 
+	hisi_pcie_handle_error(pdev, error_data);

And how exactly _platform_ device pointer is being used?

Quoted 8 lines

...

Review

Quoted 1 line
(quoted diff) +1 -0
+		dev_err(&pdev->dev, "%s : ghes_register_event_notifier

fail\n",

drivers/pci/controller/pcie-hisi-error.c line 270

Quoted 1 line
drivers/pci/controller/pcie-hisi-error.c new file +1 -0
+			__func__);

Make error message more descriptive that __func__ will not be needed.

Ok. Will fix.

Quoted 6 lines

...

drivers/pci/controller/pcie-hisi-error.c line 284

Quoted 1 line
drivers/pci/controller/pcie-hisi-error.c new file +1 -0
+	kfree(priv);

Double free?

Check was deleted on previous comment that remove for the platform device will not be called if it already freed. "The remove function isn't called on stuff which hasn't been allocated."

Quoted 7 lines

...

drivers/pci/controller/pcie-hisi-error.c line 290

Quoted 2 lines
drivers/pci/controller/pcie-hisi-error.c new file +2 -0
+static const struct acpi_device_id hisi_pcie_acpi_match[] = {
+	{ "HISI0361", 0 },

', 0' part is not necessary to have.

May be we will keep as it is.

Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+	{ }
+};

--
With Best Regards,
Andy Shevchenko

Thanks,
Shiju

#3 lore raw
Quoted 15 lines · Shiju Jose
Quoted 15 lines

-----Original Message-----
From: Andy Shevchenko [mailto:[email protected]]
Sent: 15 June 2020 13:01
To: Shiju Jose <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wangkefeng (OS Kernel Lab) <[email protected]>; [email protected]; yangyicong <[email protected]>; Jonathan Cameron <[email protected]>; tanxiaofei <[email protected]>
Subject: Re: [PATCH v9 2/2] PCI: hip: Add handling of HiSilicon HIP PCIe controller errors

On Mon, Jun 15, 2020 at 11:15:52AM +0100, Shiju Jose wrote:

...

Quoted 3 lines
Quoted 1 line

bits.h ?

Ok. I think bits.h was already included through some other .h files.

You have direct users of the header here.
The rule of thumb is to include all headers of which you have direct users. Some exceptions of course can be applied, but for generic headers like bits.h there are only bitops.h or bitmap.h that guarantee inclusion of the mentioned macros / definitions.

I don't see any header of the same domain in the list.

...

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

+#define HISI_PCIE_CORE_PORT_ID(v) (((v) % 8) << 1)

% -> & ?

(((v) % 8) << 1) is correct. We can make bit operation instead.

y % x is usually being used when we consume y / x or in cases when y is advanced and we need to keep it under some threshold.

Here it's not obvious to me, and usual pattern is to use bitwise operations.

In any case some clarification is needed.

...

Quoted 7 lines
Quoted 5 lines

drivers/pci/controller/pcie-hisi-error.c line 66

Quoted 3 lines
drivers/pci/controller/pcie-hisi-error.c new file +3 -0
+struct hisi_pcie_error_private {
+	struct notifier_block	nb;
+	struct platform_device	*pdev;

Do you really need platform device? Isn't struct device * enough?

We need platform device as the error recovery device is a platform device, which provides us the "RST" reset method.

Can't you derive platform device from struct device pointer? I really didn't see an evidence you need to keep it like this.

And in probably single case you may derive it, no?

Quoted 1 line
Quoted 1 line
Quoted 1 line

+};

...

Quoted 11 lines
Quoted 10 lines

drivers/pci/controller/pcie-hisi-error.c line 77

Quoted 8 lines
drivers/pci/controller/pcie-hisi-error.c new file +8 -0
+static char *hisi_pcie_sub_module_name(u8 id) {
+	switch (id) {
+	case HISI_PCIE_SUB_MODULE_ID_AP: return "AP Layer";
+	case HISI_PCIE_SUB_MODULE_ID_TL: return "TL Layer";
+	case HISI_PCIE_SUB_MODULE_ID_MAC: return "MAC Layer";
+	case HISI_PCIE_SUB_MODULE_ID_DL: return "DL Layer";
+	case HISI_PCIE_SUB_MODULE_ID_SDI: return "SDI Layer";
+	}

match_string() ?

Quoted 2 lines

match_string() does not work here because we need sub module id -> string conversion.

Why? Are you using non-sequential (a.k.a. sparse) values?

Quoted 14 lines
Quoted 13 lines

drivers/pci/controller/pcie-hisi-error.c line 89

Quoted 11 lines
drivers/pci/controller/pcie-hisi-error.c new file +10 -0
+	return "unknown";
 
+}
+
+static char *hisi_pcie_error_severity(u8 err_sev) {
+	switch (err_sev) {
+	case HISI_ERR_SEV_RECOVERABLE: return "recoverable";
+	case HISI_ERR_SEV_FATAL: return "fatal";
+	case HISI_ERR_SEV_CORRECTED: return "corrected";
+	case HISI_ERR_SEV_NONE: return "none";
+	}

Ditto?

Quoted 1 line

Same as above.

Ditto.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
(quoted diff) +2 -0
+	return "unknown";
+}

...

Quoted 9 lines
Quoted 6 lines

drivers/pci/controller/pcie-hisi-error.c

Quoted 3 lines
drivers/pci/controller/pcie-hisi-error.c new file +3 -0
+	for (i = 0; i < HISI_PCIE_ERR_MISC_REGS; i++) {
+		if (edata->val_bits &
+				BIT_ULL(HISI_PCIE_LOCAL_VALID_ERR_MISC

+ i))

for_each_set_bit() ?

Can't use for_each_set_bit() here because edata->val_bits contains valid bits for other fields of the error data as well, those need to printed separately.

So, I don't get why.

You have at least two possibilities:
1/ use bitwise & to drop non-related bits (maybe in temporary variable) 2/ use for_each_set_bit_from()

You really need to know better the kernel libraries.

...

Quoted 6 lines
Quoted 4 lines

drivers/pci/controller/pcie-hisi-error.c line 237

Quoted 2 lines
drivers/pci/controller/pcie-hisi-error.c new file +2 -0
+	const struct hisi_pcie_error_data *error_data =
+				acpi_hest_get_payload(gdata);

One line is better to read.

Checkpatch warning, the length of line will exceed 80 characters.

No, it doesn't. Perhaps time to update?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#4 lore raw

Hi Andy,

Quoted 39 lines

-----Original Message-----
From: [email protected] [mailto:linux-acpi- [email protected]] On Behalf Of Andy Shevchenko
Sent: 16 June 2020 10:31
To: Shiju Jose <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wangkefeng (OS Kernel Lab) <[email protected]>; [email protected]; yangyicong <[email protected]>; Jonathan Cameron <[email protected]>; tanxiaofei <[email protected]>; Linuxarm <[email protected]>
Subject: Re: [PATCH v9 2/2] PCI: hip: Add handling of HiSilicon HIP PCIe controller errors

Quoted 15 lines · Shiju Jose
Quoted 15 lines

-----Original Message-----
From: Andy Shevchenko [mailto:[email protected]]
Sent: 15 June 2020 13:01
To: Shiju Jose <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wangkefeng (OS Kernel Lab) <[email protected]>; [email protected]; yangyicong <[email protected]>; Jonathan Cameron <[email protected]>; tanxiaofei <[email protected]>
Subject: Re: [PATCH v9 2/2] PCI: hip: Add handling of HiSilicon HIP PCIe controller errors

On Mon, Jun 15, 2020 at 11:15:52AM +0100, Shiju Jose wrote:

...

Quoted 3 lines
Quoted 1 line

bits.h ?

Ok. I think bits.h was already included through some other .h files.

Quoted 7 lines

You have direct users of the header here.
The rule of thumb is to include all headers of which you have direct users. Some exceptions of course can be applied, but for generic headers like bits.h there are only bitops.h or bitmap.h that guarantee inclusion of the mentioned macros / definitions.

I don't see any header of the same domain in the list.

Ok.

Quoted 6 lines

...

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

+#define HISI_PCIE_CORE_PORT_ID(v) (((v) % 8) << 1)

% -> & ?

Quoted 8 lines
Quoted 1 line

(((v) % 8) << 1) is correct. We can make bit operation instead.

y % x is usually being used when we consume y / x or in cases when y is advanced and we need to keep it under some threshold.

Here it's not obvious to me, and usual pattern is to use bitwise operations.

In any case some clarification is needed.

We want (v % 8) * 2 here to get the core port id, a numerical value but not a bit mask. Maybe you want us to use ((v) & 7) << 1?
please point it out if I understand wrong.

Quoted 8 lines

...

Quoted 5 lines
Quoted 5 lines

drivers/pci/controller/pcie-hisi-error.c line 66

Quoted 3 lines
drivers/pci/controller/pcie-hisi-error.c new file +3 -0
+struct hisi_pcie_error_private {
+	struct notifier_block	nb;
+	struct platform_device	*pdev;

Do you really need platform device? Isn't struct device * enough?

Quoted 7 lines
Quoted 2 lines

We need platform device as the error recovery device is a platform device, which provides us the "RST" reset method.

Can't you derive platform device from struct device pointer? I really didn't see an evidence you need to keep it like this.

And in probably single case you may derive it, no?

We will check by making this change.

Quoted 16 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+};

...

Quoted 11 lines
Quoted 10 lines

drivers/pci/controller/pcie-hisi-error.c line 77

Quoted 8 lines
drivers/pci/controller/pcie-hisi-error.c new file +8 -0
+static char *hisi_pcie_sub_module_name(u8 id) {
+	switch (id) {
+	case HISI_PCIE_SUB_MODULE_ID_AP: return "AP Layer";
+	case HISI_PCIE_SUB_MODULE_ID_TL: return "TL Layer";
+	case HISI_PCIE_SUB_MODULE_ID_MAC: return "MAC Layer";
+	case HISI_PCIE_SUB_MODULE_ID_DL: return "DL Layer";
+	case HISI_PCIE_SUB_MODULE_ID_SDI: return "SDI Layer";
+	}

match_string() ?

Quoted 4 lines
Quoted 2 lines

match_string() does not work here because we need sub module id -> string conversion.

Why? Are you using non-sequential (a.k.a. sparse) values?

These are the sequential values.
I mean in this case we do not have the third parameter to the match_string(), string to match with the strings in the array,
we just have the value for the sub module id.
Can you suggest some example of match_string()
for the similar case?

Quoted 2 lines

...

Quoted 11 lines

...

Quoted 9 lines
Quoted 6 lines

drivers/pci/controller/pcie-hisi-error.c

Quoted 3 lines
drivers/pci/controller/pcie-hisi-error.c new file +3 -0
+	for (i = 0; i < HISI_PCIE_ERR_MISC_REGS; i++) {
+		if (edata->val_bits &
+				BIT_ULL(HISI_PCIE_LOCAL_VALID_ERR_MISC

+ i))

for_each_set_bit() ?

Can't use for_each_set_bit() here because edata->val_bits contains valid bits for other fields of the error data as well, those need to printed

Quoted 7 lines

separately.

So, I don't get why.

You have at least two possibilities:
1/ use bitwise & to drop non-related bits (maybe in temporary variable) 2/ use for_each_set_bit_from()

Ok. I think for_each_set_bit_from() may be better.

Quoted 2 lines

Thanks,
Shiju

#5 lore raw
Quoted 5 lines · Shiju Jose
Quoted 5 lines

From: [email protected] [mailto:linux-acpi- [email protected]] On Behalf Of Andy Shevchenko

Quoted 2 lines · Shiju Jose
Quoted 2 lines

From: Andy Shevchenko [mailto:[email protected]] On Mon, Jun 15, 2020 at 11:15:52AM +0100, Shiju Jose wrote:

...

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

+#define HISI_PCIE_CORE_PORT_ID(v) (((v) % 8) << 1)

% -> & ?

(((v) % 8) << 1) is correct. We can make bit operation instead.

y % x is usually being used when we consume y / x or in cases when y is advanced and we need to keep it under some threshold.

Quoted 6 lines
Quoted 3 lines

Here it's not obvious to me, and usual pattern is to use bitwise operations.

In any case some clarification is needed.

We want (v % 8) * 2 here to get the core port id, a numerical value but not a bit mask. Maybe you want us to use ((v) & 7) << 1?
please point it out if I understand wrong.

I understand the result, I do not understand the properties of v.
So, looks like
a) (v & 7) << 1 // take 3 LSBs from v and shift right to get port id pair (looks like)
b) (v % 8) * 2 // get next free port or circle over 0 if no free pair found

Add some comment explaining what's going on.

...

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 9 lines

drivers/pci/controller/pcie-hisi-error.c line 77

Quoted 7 lines
drivers/pci/controller/pcie-hisi-error.c new file +7 -0
+	switch (id) {
+	case HISI_PCIE_SUB_MODULE_ID_AP: return "AP Layer";
+	case HISI_PCIE_SUB_MODULE_ID_TL: return "TL Layer";
+	case HISI_PCIE_SUB_MODULE_ID_MAC: return "MAC Layer";
+	case HISI_PCIE_SUB_MODULE_ID_DL: return "DL Layer";
+	case HISI_PCIE_SUB_MODULE_ID_SDI: return "SDI Layer";
+	}

match_string() ?

match_string() does not work here because we need sub module id -> string conversion.

Quoted 7 lines
Quoted 1 line

Why? Are you using non-sequential (a.k.a. sparse) values?

These are the sequential values.
I mean in this case we do not have the third parameter to the match_string(), string to match with the strings in the array,
we just have the value for the sub module id.
Can you suggest some example of match_string()
for the similar case?

Ah, I realize, this is the opposite, but still perhaps better to have like this:

static const char * const foo[] = {
	"AB",
	"CD",
};

const char *bar(int id)

{
	if (id >= ARRAY_SIZE(foo))
		return "unknown"; // whatever
	return foo[id];
}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#6 lore raw

Hi Andy,

Quoted 41 lines

-----Original Message-----
From: Andy Shevchenko [mailto:[email protected]]
Sent: 16 June 2020 13:41
To: Shiju Jose <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wangkefeng (OS Kernel Lab) <[email protected]>; [email protected]; yangyicong <[email protected]>; Jonathan Cameron <[email protected]>; tanxiaofei <[email protected]>; Linuxarm <[email protected]>
Subject: Re: [PATCH v9 2/2] PCI: hip: Add handling of HiSilicon HIP PCIe controller errors

Quoted 5 lines · Shiju Jose
Quoted 5 lines

From: [email protected] [mailto:linux-acpi- [email protected]] On Behalf Of Andy Shevchenko On Tue, Jun 16,

Quoted 2 lines · Shiju Jose
Quoted 2 lines

From: Andy Shevchenko [mailto:[email protected]] On Mon, Jun 15, 2020 at 11:15:52AM +0100, Shiju Jose wrote:

...

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

+#define HISI_PCIE_CORE_PORT_ID(v) (((v) % 8) << 1)

% -> & ?

(((v) % 8) << 1) is correct. We can make bit operation instead.

y % x is usually being used when we consume y / x or in cases when y is advanced and we need to keep it under some threshold.

Here it's not obvious to me, and usual pattern is to use bitwise

operations.

Quoted 3 lines
Quoted 2 lines

In any case some clarification is needed.

We want (v % 8) * 2 here to get the core port id, a numerical value but not

a bit mask.

Quoted 2 lines

Maybe you want us to use ((v) & 7) << 1?
please point it out if I understand wrong.

Quoted 7 lines

I understand the result, I do not understand the properties of v. So, looks like
a) (v & 7) << 1 // take 3 LSBs from v and shift right to get port id pair (looks like)
b) (v % 8) * 2 // get next free port or circle over 0 if no free pair found

Add some comment explaining what's going on.

Sure.

Quoted 30 lines

...

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 9 lines

drivers/pci/controller/pcie-hisi-error.c line 77

Quoted 7 lines
drivers/pci/controller/pcie-hisi-error.c new file +7 -0
+	switch (id) {
+	case HISI_PCIE_SUB_MODULE_ID_AP: return "AP Layer";
+	case HISI_PCIE_SUB_MODULE_ID_TL: return "TL Layer";
+	case HISI_PCIE_SUB_MODULE_ID_MAC: return "MAC Layer";
+	case HISI_PCIE_SUB_MODULE_ID_DL: return "DL Layer";
+	case HISI_PCIE_SUB_MODULE_ID_SDI: return "SDI Layer";
+	}

match_string() ?

match_string() does not work here because we need sub module id -> string conversion.

Quoted 6 lines
Quoted 1 line

Why? Are you using non-sequential (a.k.a. sparse) values?

These are the sequential values.
I mean in this case we do not have the third parameter to the match_string(), string to match with the strings in the array, we just have the value for the sub module id.
Can you suggest some example of match_string() for the similar case?

Ah, I realize, this is the opposite, but still perhaps better to have like this:

static const char * const foo[] = {
	"AB",
	"CD",
};
Quoted 6 lines

const char *bar(int id)

{
	if (id >= ARRAY_SIZE(foo))
		return "unknown"; // whatever
	return foo[id];
}

Sure.

Quoted 5 lines

--
With Best Regards,
Andy Shevchenko

Thanks,
Shiju

#7 lore raw
In reply to Shiju Jose
Quoted 23 lines · Shiju Jose

From: Yicong Yang <[email protected]>

The HiSilicon HIP PCIe controller is capable of handling errors on root port and perform port reset separately at each root port.

Add error handling driver for HIP PCIe controller to log and report recoverable errors. Perform root port reset and restore link status after the recovery.

Following are some of the PCIe controller's recoverable errors
1. completion transmission timeout error.
2. CRS retry counter over the threshold error.
3. ECC 2 bit errors
4. AXI bresponse/rresponse errors etc.

drivers/pci/controller/pcie-hisi-error.c new file +8 -0
+static int hisi_pcie_notify_error(struct notifier_block *nb,
+				  unsigned long event, void *data)
+{
+	struct acpi_hest_generic_data *gdata = data;
+	const struct hisi_pcie_error_data *error_data =
+				acpi_hest_get_payload(gdata);
+	struct hisi_pcie_error_private *priv =
+			container_of(nb, struct hisi_pcie_error_private, nb);

drivers/pci/controller/pcie-hisi-error.c line 249

Quoted 10 lines
drivers/pci/controller/pcie-hisi-error.c new file +10 -0
+	struct platform_device *pdev = priv->pdev;
+	struct device *dev = &pdev->dev;
+	u8 socket;
+
+	if (device_property_read_u8(dev, "socket", &socket))
+		return NOTIFY_DONE;
+
+	if (!guid_equal((guid_t *)gdata->section_type, &hisi_pcie_sec_type) ||
+	    error_data->socket_id != socket)
+		return NOTIFY_DONE;

I think you have to verify the GUID first before you can even safely extract a struct hisi_pcie_error_private from the payload:

if (!guid_equal(...))

    return NOTIFY_DONE;
  priv = container_of(nb, struct hisi_pcie_error_private, nb);
  pdev = priv->pdev;
  dev = &pdev->dev;

if (device_property_read_u8(dev, "socket", &socket))

    return NOTIFY_DONE;

if (error_data->socket_id != socket)

    return NOTIFY_DONE;
Quoted 4 lines
drivers/pci/controller/pcie-hisi-error.c new file +4 -0
+	hisi_pcie_handle_error(pdev, error_data);
+
+	return NOTIFY_OK;
+}
#8 lore raw
Quoted 10 lines · Bjorn Helgaas

drivers/pci/controller/pcie-hisi-error.c line 249

Quoted 5 lines · Shiju Jose

From: Yicong Yang <[email protected]>

drivers/pci/controller/pcie-hisi-error.c new file +3 -0
+	if (!guid_equal((guid_t *)gdata->section_type, &hisi_pcie_sec_type) ||
+	    error_data->socket_id != socket)
+		return NOTIFY_DONE;

I think you have to verify the GUID first before you can even safely extract a struct hisi_pcie_error_private from the payload:

Quoted 2 lines

if (!guid_equal(...))

    return NOTIFY_DONE;

I just also noticed the ugly cast there.

So, please import GUID first (import_guid() I think is what you need).

Signature · 2 lines
With Best Regards,
Andy Shevchenko