Skip to content

Commit 7fe07d1

Browse files
author
Christoph Hellwig
committed
nvme-pci: merge nvme_free_iod into nvme_unmap_data
This means we now have a function that undoes everything nvme_map_data does and we can simplify the error handling a bit. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]>
1 parent 915f04c commit 7fe07d1

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

drivers/nvme/host/pci.c

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -583,14 +583,24 @@ static inline bool nvme_pci_use_sgls(struct nvme_dev *dev, struct request *req)
583583
return true;
584584
}
585585

586-
static void nvme_free_iod(struct nvme_dev *dev, struct request *req)
586+
static void nvme_unmap_data(struct nvme_dev *dev, struct request *req)
587587
{
588588
struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
589+
enum dma_data_direction dma_dir = rq_data_dir(req) ?
590+
DMA_TO_DEVICE : DMA_FROM_DEVICE;
589591
const int last_prp = dev->ctrl.page_size / sizeof(__le64) - 1;
590592
dma_addr_t dma_addr = iod->first_dma, next_dma_addr;
591-
592593
int i;
593594

595+
if (iod->nents) {
596+
/* P2PDMA requests do not need to be unmapped */
597+
if (!is_pci_p2pdma_page(sg_page(iod->sg)))
598+
dma_unmap_sg(dev->dev, iod->sg, iod->nents, dma_dir);
599+
600+
if (blk_integrity_rq(req))
601+
dma_unmap_sg(dev->dev, &iod->meta_sg, 1, dma_dir);
602+
}
603+
594604
if (iod->npages == 0)
595605
dma_pool_free(dev->prp_small_pool, nvme_pci_iod_list(req)[0],
596606
dma_addr);
@@ -847,50 +857,30 @@ static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
847857
ret = nvme_pci_setup_prps(dev, req, &cmnd->rw);
848858

849859
if (ret != BLK_STS_OK)
850-
goto out_unmap;
860+
goto out;
851861

852862
ret = BLK_STS_IOERR;
853863
if (blk_integrity_rq(req)) {
854864
if (blk_rq_count_integrity_sg(q, req->bio) != 1)
855-
goto out_unmap;
865+
goto out;
856866

857867
sg_init_table(&iod->meta_sg, 1);
858868
if (blk_rq_map_integrity_sg(q, req->bio, &iod->meta_sg) != 1)
859-
goto out_unmap;
869+
goto out;
860870

861871
if (!dma_map_sg(dev->dev, &iod->meta_sg, 1, dma_dir))
862-
goto out_unmap;
872+
goto out;
863873

864874
cmnd->rw.metadata = cpu_to_le64(sg_dma_address(&iod->meta_sg));
865875
}
866876

867877
return BLK_STS_OK;
868878

869-
out_unmap:
870-
dma_unmap_sg(dev->dev, iod->sg, iod->nents, dma_dir);
871879
out:
872-
nvme_free_iod(dev, req);
880+
nvme_unmap_data(dev, req);
873881
return ret;
874882
}
875883

876-
static void nvme_unmap_data(struct nvme_dev *dev, struct request *req)
877-
{
878-
struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
879-
enum dma_data_direction dma_dir = rq_data_dir(req) ?
880-
DMA_TO_DEVICE : DMA_FROM_DEVICE;
881-
882-
if (iod->nents) {
883-
/* P2PDMA requests do not need to be unmapped */
884-
if (!is_pci_p2pdma_page(sg_page(iod->sg)))
885-
dma_unmap_sg(dev->dev, iod->sg, iod->nents, dma_dir);
886-
887-
if (blk_integrity_rq(req))
888-
dma_unmap_sg(dev->dev, &iod->meta_sg, 1, dma_dir);
889-
}
890-
891-
nvme_free_iod(dev, req);
892-
}
893-
894884
/*
895885
* NOTE: ns is NULL when called on the admin queue.
896886
*/

0 commit comments

Comments
 (0)