[PATCH v2 2/2] nvme: handle persistent internal error AER from NVMe controller

From: Michael Kelley
Date: Fri Jun 03 2022 - 14:16:55 EST


In the NVM Express Revision 1.4 spec, Figure 145 describes possible
values for an AER with event type "Error" (value 000b). For a
Persistent Internal Error (value 03h), the host should perform a
controller reset.

Add support for this error using code that already exists for
doing a controller reset in response to a request timeout.

This new support was tested in a lab environment where we can
generate the persistent internal error on demand, and observe
both the Linux side and NVMe controller side to see that the
controller reset has been done.

Signed-off-by: Michael Kelley <mikelley@xxxxxxxxxxxxx>
---
drivers/nvme/host/core.c | 23 +++++++++++++++++++++++
include/linux/nvme.h | 4 ++++
2 files changed, 27 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index ea9ed04..1169583 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -4556,11 +4556,25 @@ static void nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result)
}
}

+static void nvme_handle_aer_persistent_error(struct nvme_ctrl *ctrl)
+{
+ u32 csts;
+
+ trace_nvme_async_event(ctrl, NVME_AER_ERROR);
+
+ if (ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts) != 0 ||
+ nvme_should_reset(ctrl, csts)) {
+ dev_warn(ctrl->device, "resetting controller due to AER\n");
+ nvme_reset_ctrl(ctrl);
+ }
+}
+
void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
volatile union nvme_result *res)
{
u32 result = le32_to_cpu(res->u32);
u32 aer_type = result & 0x07;
+ u32 aer_subtype = (result & 0xff00) >> 8;

if (le16_to_cpu(status) >> 1 != NVME_SC_SUCCESS)
return;
@@ -4570,6 +4584,15 @@ void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
nvme_handle_aen_notice(ctrl, result);
break;
case NVME_AER_ERROR:
+ /*
+ * For a persistent internal error, don't run async_event_work
+ * to submit a new AER. The controller reset will do it.
+ */
+ if (aer_subtype == NVME_AER_ERROR_PERSIST_INT_ERR) {
+ nvme_handle_aer_persistent_error(ctrl);
+ return;
+ }
+ fallthrough;
case NVME_AER_SMART:
case NVME_AER_CSS:
case NVME_AER_VS:
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 29ec3e3..8ced243 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -712,6 +712,10 @@ enum {
};

enum {
+ NVME_AER_ERROR_PERSIST_INT_ERR = 0x03,
+};
+
+enum {
NVME_AER_NOTICE_NS_CHANGED = 0x00,
NVME_AER_NOTICE_FW_ACT_STARTING = 0x01,
NVME_AER_NOTICE_ANA = 0x03,
--
1.8.3.1