[PATCH 05/14] nvme-core: add helper to init ctrl transport attr
Chaitanya Kulkarni
chaitanya.kulkarni at wdc.com
Tue Feb 16 19:10:23 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_identify_transport() to initialize transport-related fields.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
drivers/nvme/host/core.c | 71 ++++++++++++++++++++++------------------
1 file changed, 40 insertions(+), 31 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 840c32c755b2..f5b8f8e0ee18 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3057,6 +3057,43 @@ static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
return 0;
}
+static int nvme_init_identify_transport(struct nvme_ctrl *ctrl,
+ struct nvme_id_ctrl *id)
+{
+ if (ctrl->ops->flags & NVME_F_FABRICS) {
+ ctrl->icdoff = le16_to_cpu(id->icdoff);
+ ctrl->ioccsz = le32_to_cpu(id->ioccsz);
+ ctrl->iorcsz = le32_to_cpu(id->iorcsz);
+ ctrl->maxcmd = le16_to_cpu(id->maxcmd);
+
+ /*
+ * In fabrics we need to verify the cntlid matches the
+ * admin connect
+ */
+ if (ctrl->cntlid != le16_to_cpu(id->cntlid)) {
+ dev_err(ctrl->device,
+ "Mismatching cntlid: Connect %u vs Identify "
+ "%u, rejecting\n",
+ ctrl->cntlid, le16_to_cpu(id->cntlid));
+ return -EINVAL;
+ }
+
+ if (!nvme_discovery_ctrl(ctrl) && !ctrl->kas) {
+ dev_err(ctrl->device,
+ "keep-alive support is mandatory for fabrics\n");
+ return -EINVAL;
+ }
+ return 0;
+ }
+
+ ctrl->hmpre = le32_to_cpu(id->hmpre);
+ ctrl->hmmin = le32_to_cpu(id->hmmin);
+ ctrl->hmminds = le32_to_cpu(id->hmminds);
+ ctrl->hmmaxd = le16_to_cpu(id->hmmaxd);
+
+ return 0;
+}
+
/*
* Initialize the cached copies of the Identify data and various controller
* register in our nvme_ctrl structure. This should be called as soon as
@@ -3176,37 +3213,9 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
}
memcpy(ctrl->psd, id->psd, sizeof(ctrl->psd));
- if (ctrl->ops->flags & NVME_F_FABRICS) {
- ctrl->icdoff = le16_to_cpu(id->icdoff);
- ctrl->ioccsz = le32_to_cpu(id->ioccsz);
- ctrl->iorcsz = le32_to_cpu(id->iorcsz);
- ctrl->maxcmd = le16_to_cpu(id->maxcmd);
-
- /*
- * In fabrics we need to verify the cntlid matches the
- * admin connect
- */
- if (ctrl->cntlid != le16_to_cpu(id->cntlid)) {
- dev_err(ctrl->device,
- "Mismatching cntlid: Connect %u vs Identify "
- "%u, rejecting\n",
- ctrl->cntlid, le16_to_cpu(id->cntlid));
- ret = -EINVAL;
- goto out_free;
- }
-
- if (!nvme_discovery_ctrl(ctrl) && !ctrl->kas) {
- dev_err(ctrl->device,
- "keep-alive support is mandatory for fabrics\n");
- ret = -EINVAL;
- goto out_free;
- }
- } else {
- ctrl->hmpre = le32_to_cpu(id->hmpre);
- ctrl->hmmin = le32_to_cpu(id->hmmin);
- ctrl->hmminds = le32_to_cpu(id->hmminds);
- ctrl->hmmaxd = le16_to_cpu(id->hmmaxd);
- }
+ ret = nvme_init_identify_transport(ctrl, id);
+ if (ret < 0)
+ goto out_free;
ret = nvme_mpath_init(ctrl, id);
if (ret < 0)
--
2.22.1
More information about the Linux-nvme
mailing list