Blob Blame History Raw
From: Hannes Reinecke <hare@suse.de>
Date: Wed, 27 Jul 2022 08:09:40 +0200
Subject: [PATCH] nvme-auth: retry command if DNR bit is not set
Patch-Mainline: submitted linux-nvme 2022/07/27
References: bsc#1201675

If the cqe returns a status with the DNR bit not set we should
retry the command; otherwise we might incur spurious failures.

Reported-by: Martin George <marting@netapp.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/nvme/host/auth.c | 9 ++++++---
 drivers/nvme/host/core.c | 3 ++-
 drivers/nvme/host/nvme.h | 2 ++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index ecdea2b67953..929377c4c3c3 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -53,7 +53,7 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid,
 	struct nvme_command cmd = {};
 	blk_mq_req_flags_t flags = nvme_auth_flags_from_qid(qid);
 	struct request_queue *q = nvme_auth_queue_from_qid(ctrl, qid);
-	int ret;
+	int ret, retries = nvme_max_retries;
 
 	cmd.auth_common.opcode = nvme_fabrics_command;
 	cmd.auth_common.secp = NVME_AUTH_DHCHAP_PROTOCOL_IDENTIFIER;
@@ -67,13 +67,16 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid,
 		cmd.auth_receive.al = cpu_to_le32(data_len);
 	}
 
+retry:
 	ret = __nvme_submit_sync_cmd(q, &cmd, NULL, data, data_len, 0,
 				     qid == 0 ? NVME_QID_ANY : qid,
 				     0, flags);
-	if (ret > 0)
+	if (ret > 0) {
+		if (!(ret & NVME_SC_DNR) && --retries)
+			goto retry;
 		dev_warn(ctrl->device,
 			"qid %d auth_send failed with status %d\n", qid, ret);
-	else if (ret < 0)
+	} else if (ret < 0)
 		dev_err(ctrl->device,
 			"qid %d auth_send failed with error %d\n", qid, ret);
 	return ret;
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 221e6612242a..927f51795ac7 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -44,9 +44,10 @@ static unsigned char shutdown_timeout = 5;
 module_param(shutdown_timeout, byte, 0644);
 MODULE_PARM_DESC(shutdown_timeout, "timeout in seconds for controller shutdown");
 
-static u8 nvme_max_retries = 5;
+u8 nvme_max_retries = 5;
 module_param_named(max_retries, nvme_max_retries, byte, 0644);
 MODULE_PARM_DESC(max_retries, "max number of retries a command may have");
+EXPORT_SYMBOL_GPL(nvme_max_retries);
 
 static unsigned long default_ps_max_latency_us = 100000;
 module_param(default_ps_max_latency_us, ulong, 0644);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 6832c2110c3b..85433c69ee73 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -25,6 +25,8 @@ extern unsigned int nvme_io_timeout;
 extern unsigned int admin_timeout;
 #define NVME_ADMIN_TIMEOUT	(admin_timeout * HZ)
 
+extern u8 nvme_max_retries;
+
 #define NVME_DEFAULT_KATO	5
 
 #ifdef CONFIG_ARCH_NO_SG_CHAIN
-- 
2.35.3