Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://git.kernel.dk/linux-block
Browse files Browse the repository at this point in the history
Pull two NVMe fixes from Jens Axboe:
 "Two important fixes for the sgl support for nvme that is new in this
  release"

* 'for-linus' of git://git.kernel.dk/linux-block:
  nvme-pci: take sglist coalescing in dma_map_sg into account
  nvme-pci: check segement valid for SGL use
  • Loading branch information
torvalds committed Jan 18, 2018
2 parents 79683f8 + b0f2853 commit cdbe3bf
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions drivers/nvme/host/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,13 @@ static void **nvme_pci_iod_list(struct request *req)
static inline bool nvme_pci_use_sgls(struct nvme_dev *dev, struct request *req)
{
struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
int nseg = blk_rq_nr_phys_segments(req);
unsigned int avg_seg_size;

avg_seg_size = DIV_ROUND_UP(blk_rq_payload_bytes(req),
blk_rq_nr_phys_segments(req));
if (nseg == 0)
return false;

avg_seg_size = DIV_ROUND_UP(blk_rq_payload_bytes(req), nseg);

if (!(dev->ctrl.sgls & ((1 << 0) | (1 << 1))))
return false;
Expand Down Expand Up @@ -722,20 +725,19 @@ static void nvme_pci_sgl_set_seg(struct nvme_sgl_desc *sge,
}

static blk_status_t nvme_pci_setup_sgls(struct nvme_dev *dev,
struct request *req, struct nvme_rw_command *cmd)
struct request *req, struct nvme_rw_command *cmd, int entries)
{
struct nvme_iod *iod = blk_mq_rq_to_pdu(req);
int length = blk_rq_payload_bytes(req);
struct dma_pool *pool;
struct nvme_sgl_desc *sg_list;
struct scatterlist *sg = iod->sg;
int entries = iod->nents, i = 0;
dma_addr_t sgl_dma;
int i = 0;

/* setting the transfer type as SGL */
cmd->flags = NVME_CMD_SGL_METABUF;

if (length == sg_dma_len(sg)) {
if (entries == 1) {
nvme_pci_sgl_set_data(&cmd->dptr.sgl, sg);
return BLK_STS_OK;
}
Expand Down Expand Up @@ -775,13 +777,9 @@ static blk_status_t nvme_pci_setup_sgls(struct nvme_dev *dev,
}

nvme_pci_sgl_set_data(&sg_list[i++], sg);

length -= sg_dma_len(sg);
sg = sg_next(sg);
entries--;
} while (length > 0);
} while (--entries > 0);

WARN_ON(entries > 0);
return BLK_STS_OK;
}

Expand All @@ -793,19 +791,21 @@ static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
enum dma_data_direction dma_dir = rq_data_dir(req) ?
DMA_TO_DEVICE : DMA_FROM_DEVICE;
blk_status_t ret = BLK_STS_IOERR;
int nr_mapped;

sg_init_table(iod->sg, blk_rq_nr_phys_segments(req));
iod->nents = blk_rq_map_sg(q, req, iod->sg);
if (!iod->nents)
goto out;

ret = BLK_STS_RESOURCE;
if (!dma_map_sg_attrs(dev->dev, iod->sg, iod->nents, dma_dir,
DMA_ATTR_NO_WARN))
nr_mapped = dma_map_sg_attrs(dev->dev, iod->sg, iod->nents, dma_dir,
DMA_ATTR_NO_WARN);
if (!nr_mapped)
goto out;

if (iod->use_sgl)
ret = nvme_pci_setup_sgls(dev, req, &cmnd->rw);
ret = nvme_pci_setup_sgls(dev, req, &cmnd->rw, nr_mapped);
else
ret = nvme_pci_setup_prps(dev, req, &cmnd->rw);

Expand Down

0 comments on commit cdbe3bf

Please sign in to comment.