[PATCH-part-2 2/9] nvme-pci: provide prp selection helper

Keith Busch kbusch at meta.com
Wed Sep 4 11:38:10 PDT 2024


From: Keith Busch <kbusch at kernel.org>

The prp selection criteria is going to get a little more complicated so
introduce a helper to make the code more readable.

Signed-off-by: Keith Busch <kbusch at kernel.org>
---
 drivers/nvme/host/pci.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 21f6aeb236a6f..1763ee1886a7f 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -528,6 +528,12 @@ static inline bool nvme_pci_use_sgls(struct nvme_dev *dev, struct request *req,
 	return avg_seg_size >= sgl_threshold;
 }
 
+static inline bool nvme_pci_use_prps(struct bio_vec *bv)
+{
+	unsigned int off = bv->bv_offset & (NVME_CTRL_PAGE_SIZE - 1);
+	return  off + bv->bv_len <= NVME_CTRL_PAGE_SIZE * 2;
+}
+
 static void nvme_free_prps(struct nvme_dev *dev, struct request *req)
 {
 	const int last_prp = NVME_CTRL_PAGE_SIZE / sizeof(__le64) - 1;
@@ -784,8 +790,7 @@ static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
 		struct bio_vec bv = req_bvec(req);
 
 		if (!is_pci_p2pdma_page(bv.bv_page)) {
-			if ((bv.bv_offset & (NVME_CTRL_PAGE_SIZE - 1)) +
-			     bv.bv_len <= NVME_CTRL_PAGE_SIZE * 2)
+			if (nvme_pci_use_prps(&bv))
 				return nvme_setup_prp_simple(dev, req,
 							     &cmnd->rw, &bv);
 
-- 
2.43.5




More information about the Linux-nvme mailing list