[RFC PATCH 2/2] nvme: derive nvme cmd opcode from struct request

Chaitanya Kulkarni kch at nvidia.com
Wed Mar 9 09:04:37 PST 2022


Instead of having 3 calls of nvme_setup_rw() with nvme command opcode as
a separate parameter have one call from nvme_setup_cmd() and derive
nvme command opcode from struct request that we are already passing to
nvme_setup_rw().

This reduces duplicate calls and break statements with removal of extra
function parameter.

Signed-off-by: Chaitanya Kulkarni <kch at nvidia.com>
---
 drivers/nvme/host/core.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index b5d36e09e763..fe6179a4a31e 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -949,12 +949,16 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns,
 }
 
 static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
-		struct request *req, struct nvme_command *cmnd,
-		enum nvme_opcode op)
+		struct request *req, struct nvme_command *cmnd)
 {
 	struct nvme_ctrl *ctrl = ns->ctrl;
 	u16 control = 0;
 	u32 dsmgmt = 0;
+	static enum nvme_opcode req_op_to_nvme_opcode[] = {
+		[REQ_OP_READ] = nvme_cmd_read,
+		[REQ_OP_WRITE] = nvme_cmd_write,
+		[REQ_OP_ZONE_APPEND] = nvme_cmd_zone_append,
+	};
 
 	if (req->cmd_flags & REQ_FUA)
 		control |= NVME_RW_FUA;
@@ -964,7 +968,8 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
 	if (req->cmd_flags & REQ_RAHEAD)
 		dsmgmt |= NVME_RW_DSM_FREQ_PREFETCH;
 
-	cmnd->rw.opcode = op;
+	/* caller already validates REQ_OP_XXX */
+	cmnd->rw.opcode = req_op_to_nvme_opcode[req_op(req)];
 	cmnd->rw.flags = 0;
 	cmnd->rw.nsid = cpu_to_le32(ns->head->ns_id);
 	cmnd->rw.rsvd2 = 0;
@@ -999,7 +1004,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
 		case NVME_NS_DPS_PI_TYPE2:
 			control |= NVME_RW_PRINFO_PRCHK_GUARD |
 					NVME_RW_PRINFO_PRCHK_REF;
-			if (op == nvme_cmd_zone_append)
+			if (req_op(req) == nvme_cmd_zone_append)
 				control |= NVME_RW_APPEND_PIREMAP;
 			cmnd->rw.reftag = cpu_to_le32(t10_pi_ref_tag(req));
 			break;
@@ -1054,13 +1059,9 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req)
 		ret = nvme_setup_discard(ns, req, cmd);
 		break;
 	case REQ_OP_READ:
-		ret = nvme_setup_rw(ns, req, cmd, nvme_cmd_read);
-		break;
 	case REQ_OP_WRITE:
-		ret = nvme_setup_rw(ns, req, cmd, nvme_cmd_write);
-		break;
 	case REQ_OP_ZONE_APPEND:
-		ret = nvme_setup_rw(ns, req, cmd, nvme_cmd_zone_append);
+		ret = nvme_setup_rw(ns, req, cmd);
 		break;
 	default:
 		WARN_ON_ONCE(1);
-- 
2.29.0




More information about the Linux-nvme mailing list