lightnvm: rename dma helper functions
[deliverable/linux.git] / drivers / nvme / host / lightnvm.c
index 6bb15e4926dc86ed8b30e5cc2c504dc29090d545..8461f5a36d147e74522e42e96efacb4d1109557f 100644 (file)
@@ -146,6 +146,14 @@ struct nvme_nvm_command {
        };
 };
 
+struct nvme_nvm_completion {
+       __le64  result;         /* Used by LightNVM to return ppa completions */
+       __le16  sq_head;        /* how much of this queue may be reclaimed */
+       __le16  sq_id;          /* submission queue that generated this entry */
+       __u16   command_id;     /* of the command which completed */
+       __le16  status;         /* did the command fail, and if so, why? */
+};
+
 #define NVME_NVM_LP_MLC_PAIRS 886
 struct nvme_nvm_lp_mlc {
        __u16                   num_pairs;
@@ -380,15 +388,15 @@ out:
 }
 
 static int nvme_nvm_get_bb_tbl(struct nvm_dev *nvmdev, struct ppa_addr ppa,
-                               int nr_blocks, nvm_bb_update_fn *update_bbtbl,
-                               void *priv)
+                                                               u8 *blks)
 {
        struct request_queue *q = nvmdev->q;
        struct nvme_ns *ns = q->queuedata;
        struct nvme_ctrl *ctrl = ns->ctrl;
        struct nvme_nvm_command c = {};
        struct nvme_nvm_bb_tbl *bb_tbl;
-       int tblsz = sizeof(struct nvme_nvm_bb_tbl) + nr_blocks;
+       int nr_blks = nvmdev->blks_per_lun * nvmdev->plane_mode;
+       int tblsz = sizeof(struct nvme_nvm_bb_tbl) + nr_blks;
        int ret = 0;
 
        c.get_bb.opcode = nvme_nvm_admin_get_bb_tbl;
@@ -420,22 +428,21 @@ static int nvme_nvm_get_bb_tbl(struct nvm_dev *nvmdev, struct ppa_addr ppa,
                goto out;
        }
 
-       if (le32_to_cpu(bb_tbl->tblks) != nr_blocks) {
+       if (le32_to_cpu(bb_tbl->tblks) != nr_blks) {
                ret = -EINVAL;
                dev_err(ctrl->dev, "bbt unsuspected blocks returned (%u!=%u)",
-                                       le32_to_cpu(bb_tbl->tblks), nr_blocks);
+                               le32_to_cpu(bb_tbl->tblks), nr_blks);
                goto out;
        }
 
-       ppa = dev_to_generic_addr(nvmdev, ppa);
-       ret = update_bbtbl(ppa, nr_blocks, bb_tbl->blk, priv);
+       memcpy(blks, bb_tbl->blk, nvmdev->blks_per_lun * nvmdev->plane_mode);
 out:
        kfree(bb_tbl);
        return ret;
 }
 
-static int nvme_nvm_set_bb_tbl(struct nvm_dev *nvmdev, struct nvm_rq *rqd,
-                                                               int type)
+static int nvme_nvm_set_bb_tbl(struct nvm_dev *nvmdev, struct ppa_addr *ppas,
+                                                       int nr_ppas, int type)
 {
        struct nvme_ns *ns = nvmdev->q->queuedata;
        struct nvme_nvm_command c = {};
@@ -443,8 +450,8 @@ static int nvme_nvm_set_bb_tbl(struct nvm_dev *nvmdev, struct nvm_rq *rqd,
 
        c.set_bb.opcode = nvme_nvm_admin_set_bb_tbl;
        c.set_bb.nsid = cpu_to_le32(ns->ns_id);
-       c.set_bb.spba = cpu_to_le64(rqd->ppa_addr.ppa);
-       c.set_bb.nlb = cpu_to_le16(rqd->nr_pages - 1);
+       c.set_bb.spba = cpu_to_le64(ppas->ppa);
+       c.set_bb.nlb = cpu_to_le16(nr_ppas - 1);
        c.set_bb.value = type;
 
        ret = nvme_submit_sync_cmd(ns->ctrl->admin_q, (struct nvme_command *)&c,
@@ -460,6 +467,7 @@ static inline void nvme_nvm_rqtocmd(struct request *rq, struct nvm_rq *rqd,
        c->ph_rw.opcode = rqd->opcode;
        c->ph_rw.nsid = cpu_to_le32(ns->ns_id);
        c->ph_rw.spba = cpu_to_le64(rqd->ppa_addr.ppa);
+       c->ph_rw.metadata = cpu_to_le64(rqd->meta_list);
        c->ph_rw.control = cpu_to_le16(rqd->flags);
        c->ph_rw.length = cpu_to_le16(rqd->nr_pages - 1);
 
@@ -471,6 +479,10 @@ static inline void nvme_nvm_rqtocmd(struct request *rq, struct nvm_rq *rqd,
 static void nvme_nvm_end_io(struct request *rq, int error)
 {
        struct nvm_rq *rqd = rq->end_io_data;
+       struct nvme_nvm_completion *cqe = rq->special;
+
+       if (cqe)
+               rqd->ppa_status = le64_to_cpu(cqe->result);
 
        nvm_end_io(rqd, error);
 
@@ -490,7 +502,8 @@ static int nvme_nvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd)
        if (IS_ERR(rq))
                return -ENOMEM;
 
-       cmd = kzalloc(sizeof(struct nvme_nvm_command), GFP_KERNEL);
+       cmd = kzalloc(sizeof(struct nvme_nvm_command) +
+                               sizeof(struct nvme_nvm_completion), GFP_KERNEL);
        if (!cmd) {
                blk_mq_free_request(rq);
                return -ENOMEM;
@@ -509,7 +522,7 @@ static int nvme_nvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd)
 
        rq->cmd = (unsigned char *)cmd;
        rq->cmd_len = sizeof(struct nvme_nvm_command);
-       rq->special = (void *)0;
+       rq->special = cmd + 1;
 
        rq->end_io_data = rqd;
 
@@ -552,10 +565,10 @@ static void *nvme_nvm_dev_dma_alloc(struct nvm_dev *dev, void *pool,
        return dma_pool_alloc(pool, mem_flags, dma_handler);
 }
 
-static void nvme_nvm_dev_dma_free(void *pool, void *ppa_list,
+static void nvme_nvm_dev_dma_free(void *pool, void *addr,
                                                        dma_addr_t dma_handler)
 {
-       dma_pool_free(pool, ppa_list, dma_handler);
+       dma_pool_free(pool, addr, dma_handler);
 }
 
 static struct nvm_dev_ops nvme_nvm_dev_ops = {
This page took 0.0283369999999999 seconds and 5 git commands to generate.