* [PATCH V2 1/5] nvme: use helper to remove duplicate code
2021-06-07 19:54 [PATCH V2 0/5] nvme: small cleanups Chaitanya Kulkarni
@ 2021-06-07 19:54 ` Chaitanya Kulkarni
2021-06-07 19:54 ` [PATCH V2 2/5] nvme-fc: add a helper to check ctrl sgl support Chaitanya Kulkarni
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-07 19:54 UTC (permalink / raw)
To: linux-nvme; +Cc: james.smart, kbusch, hch, Chaitanya Kulkarni
Add a helper nvme_validate_passthru_nsid() to validate the nsid that
removes the nsid validation and error message print code from
nvme_user_cmd() and nvme_user_cmd64().
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/nvme/host/ioctl.c | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index 2e7780ea0354..d93928d1e5bd 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -177,6 +177,20 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
metadata, meta_len, lower_32_bits(io.slba), NULL, 0);
}
+static bool nvme_validate_passthru_nsid(struct nvme_ctrl *ctrl,
+ struct nvme_ns *ns, __u32 nsid)
+{
+ if (ns && nsid != ns->head->ns_id) {
+ dev_err(ctrl->device,
+ "%s: nsid (%u) in cmd does not match nsid (%u)"
+ "of namespace\n",
+ current->comm, nsid, ns->head->ns_id);
+ return false;
+ }
+
+ return true;
+}
+
static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
struct nvme_passthru_cmd __user *ucmd)
{
@@ -192,12 +206,8 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
return -EFAULT;
if (cmd.flags)
return -EINVAL;
- if (ns && cmd.nsid != ns->head->ns_id) {
- dev_err(ctrl->device,
- "%s: nsid (%u) in cmd does not match nsid (%u) of namespace\n",
- current->comm, cmd.nsid, ns->head->ns_id);
+ if (!nvme_validate_passthru_nsid(ctrl, ns, cmd.nsid))
return -EINVAL;
- }
memset(&c, 0, sizeof(c));
c.common.opcode = cmd.opcode;
@@ -242,12 +252,8 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
return -EFAULT;
if (cmd.flags)
return -EINVAL;
- if (ns && cmd.nsid != ns->head->ns_id) {
- dev_err(ctrl->device,
- "%s: nsid (%u) in cmd does not match nsid (%u) of namespace\n",
- current->comm, cmd.nsid, ns->head->ns_id);
+ if (!nvme_validate_passthru_nsid(ctrl, ns, cmd.nsid))
return -EINVAL;
- }
memset(&c, 0, sizeof(c));
c.common.opcode = cmd.opcode;
--
2.22.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH V2 2/5] nvme-fc: add a helper to check ctrl sgl support
2021-06-07 19:54 [PATCH V2 0/5] nvme: small cleanups Chaitanya Kulkarni
2021-06-07 19:54 ` [PATCH V2 1/5] nvme: use helper to remove duplicate code Chaitanya Kulkarni
@ 2021-06-07 19:54 ` Chaitanya Kulkarni
2021-06-08 15:39 ` James Smart
2021-06-07 19:54 ` [PATCH V2 3/5] nvme-tcp: use helper for ctrl sgl check Chaitanya Kulkarni
` (3 subsequent siblings)
5 siblings, 1 reply; 8+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-07 19:54 UTC (permalink / raw)
To: linux-nvme; +Cc: james.smart, kbusch, hch, Chaitanya Kulkarni
For transports it is common to check if NVMe SGLs are supported or not
by the controller.
Add a helper instead of open coding controller SGL support and use it
in fc transport.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/nvme/host/fc.c | 2 +-
drivers/nvme/host/nvme.h | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index f183f9fa03d0..7600863f7752 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -3112,7 +3112,7 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
}
/* FC-NVME supports normal SGL Data Block Descriptors */
- if (!(ctrl->ctrl.sgls & ((1 << 0) | (1 << 1)))) {
+ if (!nvme_ctrl_sgl_supported(&ctrl->ctrl)) {
dev_err(ctrl->ctrl.device,
"Mandatory sgls are not supported!\n");
ret = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 1f397ecba16c..1aab74128d40 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -869,6 +869,14 @@ static inline void nvme_hwmon_exit(struct nvme_ctrl *ctrl)
}
#endif
+static inline bool nvme_ctrl_sgl_supported(struct nvme_ctrl *ctrl)
+{
+ if (!(ctrl->sgls & ((1 << 0) | (1 << 1))))
+ return true;
+
+ return false;
+}
+
u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
u8 opcode);
void nvme_execute_passthru_rq(struct request *rq);
--
2.22.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH V2 3/5] nvme-tcp: use helper for ctrl sgl check
2021-06-07 19:54 [PATCH V2 0/5] nvme: small cleanups Chaitanya Kulkarni
2021-06-07 19:54 ` [PATCH V2 1/5] nvme: use helper to remove duplicate code Chaitanya Kulkarni
2021-06-07 19:54 ` [PATCH V2 2/5] nvme-fc: add a helper to check ctrl sgl support Chaitanya Kulkarni
@ 2021-06-07 19:54 ` Chaitanya Kulkarni
2021-06-07 19:54 ` [PATCH V2 4/5] nvme-pci: " Chaitanya Kulkarni
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-07 19:54 UTC (permalink / raw)
To: linux-nvme; +Cc: james.smart, kbusch, hch, Chaitanya Kulkarni
Use helper to check the controller's SGL support instead of open coding.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/nvme/host/tcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 5fc6c568c626..8d279aacb027 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -1992,7 +1992,7 @@ static int nvme_tcp_setup_ctrl(struct nvme_ctrl *ctrl, bool new)
goto destroy_admin;
}
- if (!(ctrl->sgls & ((1 << 0) | (1 << 1)))) {
+ if (!nvme_ctrl_sgl_supported(ctrl)) {
dev_err(ctrl->device, "Mandatory sgls are not supported!\n");
goto destroy_admin;
}
--
2.22.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH V2 4/5] nvme-pci: use helper for ctrl sgl check
2021-06-07 19:54 [PATCH V2 0/5] nvme: small cleanups Chaitanya Kulkarni
` (2 preceding siblings ...)
2021-06-07 19:54 ` [PATCH V2 3/5] nvme-tcp: use helper for ctrl sgl check Chaitanya Kulkarni
@ 2021-06-07 19:54 ` Chaitanya Kulkarni
2021-06-07 19:54 ` [PATCH V2 5/5] nvme-pci: remove trailing lines for helpers Chaitanya Kulkarni
2021-06-08 16:48 ` [PATCH V2 0/5] nvme: small cleanups Christoph Hellwig
5 siblings, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-07 19:54 UTC (permalink / raw)
To: linux-nvme; +Cc: james.smart, kbusch, hch, Chaitanya Kulkarni
Use helper to check the controller's SGL support instead of open coding.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/nvme/host/pci.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 3aa7245a505f..f86ad4b7a9b6 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -536,7 +536,7 @@ static inline bool nvme_pci_use_sgls(struct nvme_dev *dev, struct request *req)
avg_seg_size = DIV_ROUND_UP(blk_rq_payload_bytes(req), nseg);
- if (!(dev->ctrl.sgls & ((1 << 0) | (1 << 1))))
+ if (!nvme_ctrl_sgl_supported(&dev->ctrl))
return false;
if (!iod->nvmeq->qid)
return false;
@@ -855,7 +855,7 @@ static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
&cmnd->rw, &bv);
if (iod->nvmeq->qid && sgl_threshold &&
- dev->ctrl.sgls & ((1 << 0) | (1 << 1)))
+ nvme_ctrl_sgl_supported(&dev->ctrl))
return nvme_setup_sgl_simple(dev, req,
&cmnd->rw, &bv);
}
--
2.22.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH V2 5/5] nvme-pci: remove trailing lines for helpers
2021-06-07 19:54 [PATCH V2 0/5] nvme: small cleanups Chaitanya Kulkarni
` (3 preceding siblings ...)
2021-06-07 19:54 ` [PATCH V2 4/5] nvme-pci: " Chaitanya Kulkarni
@ 2021-06-07 19:54 ` Chaitanya Kulkarni
2021-06-08 16:48 ` [PATCH V2 0/5] nvme: small cleanups Christoph Hellwig
5 siblings, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-07 19:54 UTC (permalink / raw)
To: linux-nvme; +Cc: james.smart, kbusch, hch, Chaitanya Kulkarni
Remove the extra white line at the end of the functions.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/nvme/host/pci.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index f86ad4b7a9b6..6933f843f3f2 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -559,7 +559,6 @@ static void nvme_free_prps(struct nvme_dev *dev, struct request *req)
dma_pool_free(dev->prp_page_pool, prp_list, dma_addr);
dma_addr = next_dma_addr;
}
-
}
static void nvme_free_sgls(struct nvme_dev *dev, struct request *req)
@@ -576,7 +575,6 @@ static void nvme_free_sgls(struct nvme_dev *dev, struct request *req)
dma_pool_free(dev->prp_page_pool, sg_list, dma_addr);
dma_addr = next_dma_addr;
}
-
}
static void nvme_unmap_sg(struct nvme_dev *dev, struct request *req)
--
2.22.1
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH V2 0/5] nvme: small cleanups
2021-06-07 19:54 [PATCH V2 0/5] nvme: small cleanups Chaitanya Kulkarni
` (4 preceding siblings ...)
2021-06-07 19:54 ` [PATCH V2 5/5] nvme-pci: remove trailing lines for helpers Chaitanya Kulkarni
@ 2021-06-08 16:48 ` Christoph Hellwig
5 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2021-06-08 16:48 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: linux-nvme, james.smart, kbusch, hch
Thanks,
I've applied patches 1, 4 and 5 to nvme-5.14. Please resend 2 and 3
as they don't apply to the current tree.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 8+ messages in thread