Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] nvme: small cleanups
@ 2021-06-07  0:37 Chaitanya Kulkarni
  2021-06-07  0:37 ` [PATCH 1/5] nvme: use helper to remove duplicate code Chaitanya Kulkarni
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-07  0:37 UTC (permalink / raw)
  To: linux-nvme; +Cc: james.smart, kbusch, hch, Chaitanya Kulkarni

Hi,

This adds a couple of helpers to remove the duplicate code. The last
patch removes the exta white lines from nvme-pci.

If this makes sense, please consider this series for 5.14.

-ck

Chaitanya Kulkarni (5):
  nvme: use helper to remove duplicate code
  nvme-fc: add a helper to check ctrl sgl support
  nvme-tcp: use helper for ctrl sgl check
  nvme-pci: use helper for ctrl sgl check
  nvme-pci: remove trailing lines for helpers

 drivers/nvme/host/fc.c    |  2 +-
 drivers/nvme/host/ioctl.c | 26 ++++++++++++++++----------
 drivers/nvme/host/nvme.h  |  8 ++++++++
 drivers/nvme/host/pci.c   |  4 +---
 drivers/nvme/host/tcp.c   |  2 +-
 5 files changed, 27 insertions(+), 15 deletions(-)

-- 
2.22.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] nvme: use helper to remove duplicate code
  2021-06-07  0:37 [PATCH 0/5] nvme: small cleanups Chaitanya Kulkarni
@ 2021-06-07  0:37 ` Chaitanya Kulkarni
  2021-06-07  0:37 ` [PATCH 2/5] nvme-fc: add a helper to check ctrl sgl support Chaitanya Kulkarni
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-07  0:37 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] 7+ messages in thread

* [PATCH 2/5] nvme-fc: add a helper to check ctrl sgl support
  2021-06-07  0:37 [PATCH 0/5] nvme: small cleanups Chaitanya Kulkarni
  2021-06-07  0:37 ` [PATCH 1/5] nvme: use helper to remove duplicate code Chaitanya Kulkarni
@ 2021-06-07  0:37 ` Chaitanya Kulkarni
  2021-06-07  0:37 ` [PATCH 3/5] nvme-tcp: use helper for ctrl sgl check Chaitanya Kulkarni
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-07  0:37 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] 7+ messages in thread

* [PATCH 3/5] nvme-tcp: use helper for ctrl sgl check
  2021-06-07  0:37 [PATCH 0/5] nvme: small cleanups Chaitanya Kulkarni
  2021-06-07  0:37 ` [PATCH 1/5] nvme: use helper to remove duplicate code Chaitanya Kulkarni
  2021-06-07  0:37 ` [PATCH 2/5] nvme-fc: add a helper to check ctrl sgl support Chaitanya Kulkarni
@ 2021-06-07  0:37 ` Chaitanya Kulkarni
  2021-06-07  0:37 ` [PATCH 4/5] nvme-pci: " Chaitanya Kulkarni
  2021-06-07  0:37 ` [PATCH 5/5] nvme-pci: remove trailing lines for helpers Chaitanya Kulkarni
  4 siblings, 0 replies; 7+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-07  0:37 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] 7+ messages in thread

* [PATCH 4/5] nvme-pci: use helper for ctrl sgl check
  2021-06-07  0:37 [PATCH 0/5] nvme: small cleanups Chaitanya Kulkarni
                   ` (2 preceding siblings ...)
  2021-06-07  0:37 ` [PATCH 3/5] nvme-tcp: use helper for ctrl sgl check Chaitanya Kulkarni
@ 2021-06-07  0:37 ` Chaitanya Kulkarni
  2021-06-07  8:02   ` Niklas Cassel
  2021-06-07  0:37 ` [PATCH 5/5] nvme-pci: remove trailing lines for helpers Chaitanya Kulkarni
  4 siblings, 1 reply; 7+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-07  0:37 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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 3aa7245a505f..a7e7afc609b4 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;
-- 
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] 7+ messages in thread

* [PATCH 5/5] nvme-pci: remove trailing lines for helpers
  2021-06-07  0:37 [PATCH 0/5] nvme: small cleanups Chaitanya Kulkarni
                   ` (3 preceding siblings ...)
  2021-06-07  0:37 ` [PATCH 4/5] nvme-pci: " Chaitanya Kulkarni
@ 2021-06-07  0:37 ` Chaitanya Kulkarni
  4 siblings, 0 replies; 7+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-07  0:37 UTC (permalink / raw)
  To: linux-nvme; +Cc: james.smart, kbusch, hch, Chaitanya Kulkarni

Remove the extra white lines 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 a7e7afc609b4..07d2bc317fba 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] 7+ messages in thread

* Re: [PATCH 4/5] nvme-pci: use helper for ctrl sgl check
  2021-06-07  0:37 ` [PATCH 4/5] nvme-pci: " Chaitanya Kulkarni
@ 2021-06-07  8:02   ` Niklas Cassel
  0 siblings, 0 replies; 7+ messages in thread
From: Niklas Cassel @ 2021-06-07  8:02 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: linux-nvme@lists.infradead.org, james.smart@broadcom.com,
	kbusch@kernel.org, hch@lst.de

On Sun, Jun 06, 2021 at 05:37:04PM -0700, Chaitanya Kulkarni wrote:
> 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 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index 3aa7245a505f..a7e7afc609b4 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;
> -- 
> 2.22.1

Hello Chaitanya,

I believe that you can apply the same cleanup for pci.c:nvme_map_data()


Kind regards,
Niklas
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-06-07  8:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-07  0:37 [PATCH 0/5] nvme: small cleanups Chaitanya Kulkarni
2021-06-07  0:37 ` [PATCH 1/5] nvme: use helper to remove duplicate code Chaitanya Kulkarni
2021-06-07  0:37 ` [PATCH 2/5] nvme-fc: add a helper to check ctrl sgl support Chaitanya Kulkarni
2021-06-07  0:37 ` [PATCH 3/5] nvme-tcp: use helper for ctrl sgl check Chaitanya Kulkarni
2021-06-07  0:37 ` [PATCH 4/5] nvme-pci: " Chaitanya Kulkarni
2021-06-07  8:02   ` Niklas Cassel
2021-06-07  0:37 ` [PATCH 5/5] nvme-pci: remove trailing lines for helpers Chaitanya Kulkarni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox