From: Keith Busch <kbusch@meta.com>
To: <linux-block@vger.kernel.org>, <linux-nvme@lists.infradead.org>
Cc: <hch@lst.de>, <axboe@kernel.dk>, <joshi.k@samsung.com>,
Keith Busch <kbusch@kernel.org>
Subject: [PATCHv4 7/8] nvme-pci: create common sgl unmapping helper
Date: Thu, 31 Jul 2025 08:05:12 -0700 [thread overview]
Message-ID: <20250731150513.220395-8-kbusch@meta.com> (raw)
In-Reply-To: <20250731150513.220395-1-kbusch@meta.com>
From: Keith Busch <kbusch@kernel.org>
This can be reused by metadata sgls once that starts using the blk-mq
dma api.
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
drivers/nvme/host/pci.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 111b6bc6c93eb..decb3ad1508a7 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -693,25 +693,34 @@ static void nvme_free_prps(struct request *req)
mempool_free(iod->dma_vecs, nvmeq->dev->dmavec_mempool);
}
+
+static void __nvme_free_sgls(struct device *dma_dev, struct nvme_sgl_desc *sge,
+ struct nvme_sgl_desc *sg_list, enum dma_data_direction dir)
+{
+ unsigned int len = le32_to_cpu(sge->length);
+ unsigned int i, nr_entries;
+
+ if (sge->type == (NVME_SGL_FMT_DATA_DESC << 4)) {
+ dma_unmap_page(dma_dev, le64_to_cpu(sge->addr), len, dir);
+ return;
+ }
+
+ nr_entries = len / sizeof(*sg_list);
+ for (i = 0; i < nr_entries; i++)
+ dma_unmap_page(dma_dev, le64_to_cpu(sg_list[i].addr),
+ le32_to_cpu(sg_list[i].length), dir);
+}
+
static void nvme_free_sgls(struct request *req)
{
struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
struct nvme_queue *nvmeq = req->mq_hctx->driver_data;
struct device *dma_dev = nvmeq->dev->dev;
- dma_addr_t sqe_dma_addr = le64_to_cpu(iod->cmd.common.dptr.sgl.addr);
- unsigned int sqe_dma_len = le32_to_cpu(iod->cmd.common.dptr.sgl.length);
struct nvme_sgl_desc *sg_list = iod->descriptors[0];
+ struct nvme_sgl_desc *sge = &iod->cmd.common.dptr.sgl;
enum dma_data_direction dir = rq_dma_dir(req);
- if (iod->nr_descriptors) {
- unsigned int nr_entries = sqe_dma_len / sizeof(*sg_list), i;
-
- for (i = 0; i < nr_entries; i++)
- dma_unmap_page(dma_dev, le64_to_cpu(sg_list[i].addr),
- le32_to_cpu(sg_list[i].length), dir);
- } else {
- dma_unmap_page(dma_dev, sqe_dma_addr, sqe_dma_len, dir);
- }
+ __nvme_free_sgls(dma_dev, sge, sg_list, dir);
}
static void nvme_unmap_data(struct request *req)
--
2.47.3
next prev parent reply other threads:[~2025-07-31 15:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-31 15:05 [PATCHv4 0/8] blk-mq: introduce blk_map_iter Keith Busch
2025-07-31 15:05 ` [PATCHv4 1/8] blk-mq-dma: " Keith Busch
2025-07-31 15:05 ` [PATCHv4 2/8] blk-mq-dma: provide the bio_vec list being iterated Keith Busch
2025-07-31 15:05 ` [PATCHv4 3/8] blk-mq-dma: require unmap caller provide p2p map type Keith Busch
2025-07-31 15:05 ` [PATCHv4 4/8] blk-mq: remove REQ_P2PDMA flag Keith Busch
2025-08-08 12:54 ` Kanchan Joshi
2025-07-31 15:05 ` [PATCHv4 5/8] blk-mq-dma: move common dma start code to a helper Keith Busch
2025-07-31 15:05 ` [PATCHv4 6/8] blk-mq-dma: add support for mapping integrity metadata Keith Busch
2025-08-02 23:11 ` kernel test robot
2025-07-31 15:05 ` Keith Busch [this message]
2025-07-31 15:05 ` [PATCHv4 8/8] nvme-pci: convert metadata mapping to dma iter Keith Busch
2025-08-08 13:01 ` Kanchan Joshi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250731150513.220395-8-kbusch@meta.com \
--to=kbusch@meta.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=joshi.k@samsung.com \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox