[PATCH 07/14] nvme-core: add helper to init ctrl subsys quirk

Chaitanya Kulkarni chaitanya.kulkarni at wdc.com
Tue Feb 16 19:10:25 EST 2021


The function nvme_init_identify() has grown over the period of time about
~200 lines given the size of nvme id_ctrl data structure.

Just like the tail of the function it has small helpers to initialize
the independent fields that needs some extra checking, add a new helper
nvme_init_ctrl_subsys_and_quirks() to initialize ctrl subsystem and
quirks.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
 drivers/nvme/host/core.c | 43 +++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 16 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 77f79a2a396f..4a59a46193e8 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3057,6 +3057,32 @@ static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
 	return 0;
 }
 
+static int nvme_init_ctrl_subsys_and_quirks(struct nvme_ctrl *ctrl,
+		struct nvme_id_ctrl *id)
+{
+	unsigned int i;
+	int ret;
+
+	ret = nvme_init_subsystem(ctrl, id);
+	if (ret)
+		return ret;
+
+	/*
+	 * Check for quirks.  Quirk can depend on firmware version,
+	 * so, in principle, the set of quirks present can change
+	 * across a reset.  As a possible future enhancement, we
+	 * could re-scan for quirks every time we reinitialize
+	 * the device, but we'd have to make sure that the driver
+	 * behaves intelligently if the quirks change.
+	 */
+	for (i = 0; i < ARRAY_SIZE(core_quirks); i++) {
+		if (quirk_matches(id, &core_quirks[i]))
+			ctrl->quirks |= core_quirks[i].quirks;
+	}
+
+	return 0;
+}
+
 static int nvme_init_identify_transport(struct nvme_ctrl *ctrl,
 		struct nvme_id_ctrl *id)
 {
@@ -3151,24 +3177,9 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
 		ctrl->cntlid = le16_to_cpu(id->cntlid);
 
 	if (!ctrl->identified) {
-		unsigned int i;
-
-		ret = nvme_init_subsystem(ctrl, id);
+		ret = nvme_init_ctrl_subsys_and_quirks(ctrl, id);
 		if (ret)
 			goto out_free;
-
-		/*
-		 * Check for quirks.  Quirk can depend on firmware version,
-		 * so, in principle, the set of quirks present can change
-		 * across a reset.  As a possible future enhancement, we
-		 * could re-scan for quirks every time we reinitialize
-		 * the device, but we'd have to make sure that the driver
-		 * behaves intelligently if the quirks change.
-		 */
-		for (i = 0; i < ARRAY_SIZE(core_quirks); i++) {
-			if (quirk_matches(id, &core_quirks[i]))
-				ctrl->quirks |= core_quirks[i].quirks;
-		}
 	}
 
 	if (force_apst && (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) {
-- 
2.22.1




More information about the Linux-nvme mailing list