[PATCH 5/9] nvme-pci: merge the simple PRP and SGL setup into a common helper
Daniel Gomez
da.gomez at kernel.org
Wed Jun 11 06:44:45 PDT 2025
On 10/06/2025 07.06, Christoph Hellwig wrote:
> nvme_setup_prp_simple and nvme_setup_sgl_simple share a lot of logic.
> Merge them into a single helper that makes use of the previously added
> use_sgl tristate.
>
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> ---
> drivers/nvme/host/pci.c | 77 +++++++++++++++++------------------------
> 1 file changed, 32 insertions(+), 45 deletions(-)
>
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index 0b85c11d3c96..50bb1ebe6810 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -814,42 +814,41 @@ static blk_status_t nvme_pci_setup_sgls(struct nvme_queue *nvmeq,
> return BLK_STS_OK;
> }
>
> -static blk_status_t nvme_setup_prp_simple(struct nvme_dev *dev,
> - struct request *req, struct nvme_rw_command *cmnd,
> - struct bio_vec *bv)
> +static blk_status_t nvme_pci_setup_data_simple(struct request *req,
> + enum nvme_use_sgl use_sgl)
> {
> struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
> - unsigned int offset = bv->bv_offset & (NVME_CTRL_PAGE_SIZE - 1);
> - unsigned int first_prp_len = NVME_CTRL_PAGE_SIZE - offset;
> -
> - iod->first_dma = dma_map_bvec(dev->dev, bv, rq_dma_dir(req), 0);
> - if (dma_mapping_error(dev->dev, iod->first_dma))
> + struct nvme_queue *nvmeq = req->mq_hctx->driver_data;
> + struct bio_vec bv = req_bvec(req);
> + unsigned int prp1_offset = bv.bv_offset & (NVME_CTRL_PAGE_SIZE - 1);
> + bool prp_possible = prp1_offset + bv.bv_len <= NVME_CTRL_PAGE_SIZE * 2;
> + dma_addr_t dma_addr;
> +
> + if (!use_sgl && !prp_possible)
> + return BLK_STS_AGAIN;
> + if (is_pci_p2pdma_page(bv.bv_page))
> + return BLK_STS_AGAIN;
> +
> + dma_addr = dma_map_bvec(nvmeq->dev->dev, &bv, rq_dma_dir(req), 0);
> + if (dma_mapping_error(nvmeq->dev->dev, dma_addr))
> return BLK_STS_RESOURCE;
> - iod->dma_len = bv->bv_len;
> -
> - cmnd->dptr.prp1 = cpu_to_le64(iod->first_dma);
> - if (bv->bv_len > first_prp_len)
> - cmnd->dptr.prp2 = cpu_to_le64(iod->first_dma + first_prp_len);
> - else
> - cmnd->dptr.prp2 = 0;
> - return BLK_STS_OK;
> -}
> + iod->dma_len = bv.bv_len;
>
> -static blk_status_t nvme_setup_sgl_simple(struct nvme_dev *dev,
> - struct request *req, struct nvme_rw_command *cmnd,
> - struct bio_vec *bv)
> -{
> - struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
> + if (use_sgl == SGL_FORCED || !prp_possible) {
I couldn't find any place other than this where the new FORCED tristate actually
matters. So instead of passing the use_sgl tristate around, why not just check
here whether SGL is forced?
More information about the Linux-nvme
mailing list