2 * Copyright (C) 2016 CNEX Labs
3 * Initial release: Javier Gonzalez <javier@cnexlabs.com>
4 * Matias Bjorling <matias@cnexlabs.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * pblk-core.c - pblk's core functionality
20 #include <linux/time.h>
22 static void pblk_mark_bb(struct pblk *pblk, struct pblk_line *line,
25 struct nvm_tgt_dev *dev = pblk->dev;
26 struct nvm_geo *geo = &dev->geo;
27 int pos = pblk_dev_ppa_to_pos(geo, *ppa);
29 pr_debug("pblk: erase failed: line:%d, pos:%d\n", line->id, pos);
30 atomic_long_inc(&pblk->erase_failed);
32 atomic_dec(&line->blk_in_line);
33 if (test_and_set_bit(pos, line->blk_bitmap))
34 pr_err("pblk: attempted to erase bb: line:%d, pos:%d\n",
37 pblk_line_run_ws(pblk, NULL, ppa, pblk_line_mark_bb);
40 static void __pblk_end_io_erase(struct pblk *pblk, struct nvm_rq *rqd)
42 struct pblk_line *line;
44 line = &pblk->lines[pblk_dev_ppa_to_line(rqd->ppa_addr)];
45 atomic_dec(&line->left_seblks);
50 ppa = kmalloc(sizeof(struct ppa_addr), GFP_ATOMIC);
55 pblk_mark_bb(pblk, line, ppa);
59 /* Erase completion assumes that only one block is erased at the time */
60 static void pblk_end_io_erase(struct nvm_rq *rqd)
62 struct pblk *pblk = rqd->private;
64 __pblk_end_io_erase(pblk, rqd);
65 mempool_free(rqd, pblk->r_rq_pool);
68 static void __pblk_map_invalidate(struct pblk *pblk, struct pblk_line *line,
71 struct pblk_line_mgmt *l_mg = &pblk->l_mg;
72 struct list_head *move_list = NULL;
74 /* Lines being reclaimed (GC'ed) cannot be invalidated. Before the L2P
75 * table is modified with reclaimed sectors, a check is done to endure
76 * that newer updates are not overwritten.
78 spin_lock(&line->lock);
79 if (line->state == PBLK_LINESTATE_GC ||
80 line->state == PBLK_LINESTATE_FREE) {
81 spin_unlock(&line->lock);
85 if (test_and_set_bit(paddr, line->invalid_bitmap)) {
86 WARN_ONCE(1, "pblk: double invalidate\n");
87 spin_unlock(&line->lock);
92 if (line->state == PBLK_LINESTATE_CLOSED)
93 move_list = pblk_line_gc_list(pblk, line);
94 spin_unlock(&line->lock);
97 spin_lock(&l_mg->gc_lock);
98 spin_lock(&line->lock);
99 /* Prevent moving a line that has just been chosen for GC */
100 if (line->state == PBLK_LINESTATE_GC ||
101 line->state == PBLK_LINESTATE_FREE) {
102 spin_unlock(&line->lock);
103 spin_unlock(&l_mg->gc_lock);
106 spin_unlock(&line->lock);
108 list_move_tail(&line->list, move_list);
109 spin_unlock(&l_mg->gc_lock);
113 void pblk_map_invalidate(struct pblk *pblk, struct ppa_addr ppa)
115 struct pblk_line *line;
119 #ifdef CONFIG_NVM_DEBUG
120 /* Callers must ensure that the ppa points to a device address */
121 BUG_ON(pblk_addr_in_cache(ppa));
122 BUG_ON(pblk_ppa_empty(ppa));
125 line_id = pblk_tgt_ppa_to_line(ppa);
126 line = &pblk->lines[line_id];
127 paddr = pblk_dev_ppa_to_line_addr(pblk, ppa);
129 __pblk_map_invalidate(pblk, line, paddr);
132 void pblk_map_pad_invalidate(struct pblk *pblk, struct pblk_line *line,
135 __pblk_map_invalidate(pblk, line, paddr);
137 pblk_rb_sync_init(&pblk->rwb, NULL);
139 if (!line->left_ssecs)
140 pblk_line_run_ws(pblk, line, NULL, pblk_line_close_ws);
141 pblk_rb_sync_end(&pblk->rwb, NULL);
144 static void pblk_invalidate_range(struct pblk *pblk, sector_t slba,
145 unsigned int nr_secs)
149 spin_lock(&pblk->trans_lock);
150 for (lba = slba; lba < slba + nr_secs; lba++) {
153 ppa = pblk_trans_map_get(pblk, lba);
155 if (!pblk_addr_in_cache(ppa) && !pblk_ppa_empty(ppa))
156 pblk_map_invalidate(pblk, ppa);
158 pblk_ppa_set_empty(&ppa);
159 pblk_trans_map_set(pblk, lba, ppa);
161 spin_unlock(&pblk->trans_lock);
164 struct nvm_rq *pblk_alloc_rqd(struct pblk *pblk, int rw)
171 pool = pblk->w_rq_pool;
172 rq_size = pblk_w_rq_size;
174 pool = pblk->r_rq_pool;
175 rq_size = pblk_r_rq_size;
178 rqd = mempool_alloc(pool, GFP_KERNEL);
179 memset(rqd, 0, rq_size);
184 void pblk_free_rqd(struct pblk *pblk, struct nvm_rq *rqd, int rw)
189 pool = pblk->w_rq_pool;
191 pool = pblk->r_rq_pool;
193 mempool_free(rqd, pool);
196 void pblk_bio_free_pages(struct pblk *pblk, struct bio *bio, int off,
202 WARN_ON(off + nr_pages != bio->bi_vcnt);
204 bio_advance(bio, off * PBLK_EXPOSED_PAGE_SIZE);
205 for (i = off; i < nr_pages + off; i++) {
206 bv = bio->bi_io_vec[i];
207 mempool_free(bv.bv_page, pblk->page_pool);
211 int pblk_bio_add_pages(struct pblk *pblk, struct bio *bio, gfp_t flags,
214 struct request_queue *q = pblk->dev->q;
218 for (i = 0; i < nr_pages; i++) {
219 page = mempool_alloc(pblk->page_pool, flags);
223 ret = bio_add_pc_page(q, bio, page, PBLK_EXPOSED_PAGE_SIZE, 0);
224 if (ret != PBLK_EXPOSED_PAGE_SIZE) {
225 pr_err("pblk: could not add page to bio\n");
226 mempool_free(page, pblk->page_pool);
233 pblk_bio_free_pages(pblk, bio, 0, i - 1);
237 static void pblk_write_kick(struct pblk *pblk)
239 wake_up_process(pblk->writer_ts);
240 mod_timer(&pblk->wtimer, jiffies + msecs_to_jiffies(1000));
243 void pblk_write_timer_fn(unsigned long data)
245 struct pblk *pblk = (struct pblk *)data;
247 /* kick the write thread every tick to flush outstanding data */
248 pblk_write_kick(pblk);
251 void pblk_write_should_kick(struct pblk *pblk)
253 unsigned int secs_avail = pblk_rb_read_count(&pblk->rwb);
255 if (secs_avail >= pblk->min_write_pgs)
256 pblk_write_kick(pblk);
259 void pblk_end_bio_sync(struct bio *bio)
261 struct completion *waiting = bio->bi_private;
266 void pblk_end_io_sync(struct nvm_rq *rqd)
268 struct completion *waiting = rqd->private;
273 void pblk_flush_writer(struct pblk *pblk)
277 DECLARE_COMPLETION_ONSTACK(wait);
279 bio = bio_alloc(GFP_KERNEL, 1);
283 bio->bi_iter.bi_sector = 0; /* internal bio */
284 bio_set_op_attrs(bio, REQ_OP_WRITE, REQ_OP_FLUSH);
285 bio->bi_private = &wait;
286 bio->bi_end_io = pblk_end_bio_sync;
288 ret = pblk_write_to_cache(pblk, bio, 0);
289 if (ret == NVM_IO_OK) {
290 if (!wait_for_completion_io_timeout(&wait,
291 msecs_to_jiffies(PBLK_COMMAND_TIMEOUT_MS))) {
292 pr_err("pblk: flush cache timed out\n");
294 } else if (ret != NVM_IO_DONE) {
295 pr_err("pblk: tear down bio failed\n");
299 pr_err("pblk: flush sync write failed (%u)\n", bio->bi_status);
304 struct list_head *pblk_line_gc_list(struct pblk *pblk, struct pblk_line *line)
306 struct pblk_line_meta *lm = &pblk->lm;
307 struct pblk_line_mgmt *l_mg = &pblk->l_mg;
308 struct list_head *move_list = NULL;
311 if (line->gc_group != PBLK_LINEGC_FULL) {
312 line->gc_group = PBLK_LINEGC_FULL;
313 move_list = &l_mg->gc_full_list;
315 } else if (line->vsc < lm->mid_thrs) {
316 if (line->gc_group != PBLK_LINEGC_HIGH) {
317 line->gc_group = PBLK_LINEGC_HIGH;
318 move_list = &l_mg->gc_high_list;
320 } else if (line->vsc < lm->high_thrs) {
321 if (line->gc_group != PBLK_LINEGC_MID) {
322 line->gc_group = PBLK_LINEGC_MID;
323 move_list = &l_mg->gc_mid_list;
325 } else if (line->vsc < line->sec_in_line) {
326 if (line->gc_group != PBLK_LINEGC_LOW) {
327 line->gc_group = PBLK_LINEGC_LOW;
328 move_list = &l_mg->gc_low_list;
330 } else if (line->vsc == line->sec_in_line) {
331 if (line->gc_group != PBLK_LINEGC_EMPTY) {
332 line->gc_group = PBLK_LINEGC_EMPTY;
333 move_list = &l_mg->gc_empty_list;
336 line->state = PBLK_LINESTATE_CORRUPT;
337 line->gc_group = PBLK_LINEGC_NONE;
338 move_list = &l_mg->corrupt_list;
339 pr_err("pblk: corrupted vsc for line %d, vsc:%d (%d/%d/%d)\n",
342 lm->high_thrs, lm->mid_thrs);
348 void pblk_discard(struct pblk *pblk, struct bio *bio)
350 sector_t slba = pblk_get_lba(bio);
351 sector_t nr_secs = pblk_get_secs(bio);
353 pblk_invalidate_range(pblk, slba, nr_secs);
356 struct ppa_addr pblk_get_lba_map(struct pblk *pblk, sector_t lba)
360 spin_lock(&pblk->trans_lock);
361 ppa = pblk_trans_map_get(pblk, lba);
362 spin_unlock(&pblk->trans_lock);
367 void pblk_log_write_err(struct pblk *pblk, struct nvm_rq *rqd)
369 atomic_long_inc(&pblk->write_failed);
370 #ifdef CONFIG_NVM_DEBUG
371 pblk_print_failed_rqd(pblk, rqd, rqd->error);
375 void pblk_log_read_err(struct pblk *pblk, struct nvm_rq *rqd)
377 /* Empty page read is not necessarily an error (e.g., L2P recovery) */
378 if (rqd->error == NVM_RSP_ERR_EMPTYPAGE) {
379 atomic_long_inc(&pblk->read_empty);
383 switch (rqd->error) {
384 case NVM_RSP_WARN_HIGHECC:
385 atomic_long_inc(&pblk->read_high_ecc);
387 case NVM_RSP_ERR_FAILECC:
388 case NVM_RSP_ERR_FAILCRC:
389 atomic_long_inc(&pblk->read_failed);
392 pr_err("pblk: unknown read error:%d\n", rqd->error);
394 #ifdef CONFIG_NVM_DEBUG
395 pblk_print_failed_rqd(pblk, rqd, rqd->error);
399 void pblk_set_sec_per_write(struct pblk *pblk, int sec_per_write)
401 pblk->sec_per_write = sec_per_write;
404 int pblk_submit_io(struct pblk *pblk, struct nvm_rq *rqd)
406 struct nvm_tgt_dev *dev = pblk->dev;
408 #ifdef CONFIG_NVM_DEBUG
409 struct ppa_addr *ppa_list;
411 ppa_list = (rqd->nr_ppas > 1) ? rqd->ppa_list : &rqd->ppa_addr;
412 if (pblk_boundary_ppa_checks(dev, ppa_list, rqd->nr_ppas)) {
417 if (rqd->opcode == NVM_OP_PWRITE) {
418 struct pblk_line *line;
422 for (i = 0; i < rqd->nr_ppas; i++) {
424 line = &pblk->lines[pblk_dev_ppa_to_line(ppa)];
426 spin_lock(&line->lock);
427 if (line->state != PBLK_LINESTATE_OPEN) {
428 pr_err("pblk: bad ppa: line:%d,state:%d\n",
429 line->id, line->state);
431 spin_unlock(&line->lock);
434 spin_unlock(&line->lock);
438 return nvm_submit_io(dev, rqd);
441 struct bio *pblk_bio_map_addr(struct pblk *pblk, void *data,
442 unsigned int nr_secs, unsigned int len,
445 struct nvm_tgt_dev *dev = pblk->dev;
446 struct pblk_line_mgmt *l_mg = &pblk->l_mg;
452 if (l_mg->emeta_alloc_type == PBLK_KMALLOC_META)
453 return bio_map_kern(dev->q, kaddr, len, gfp_mask);
455 bio = bio_kmalloc(gfp_mask, nr_secs);
457 return ERR_PTR(-ENOMEM);
459 for (i = 0; i < nr_secs; i++) {
460 page = vmalloc_to_page(kaddr);
462 pr_err("pblk: could not map vmalloc bio\n");
464 bio = ERR_PTR(-ENOMEM);
468 ret = bio_add_pc_page(dev->q, bio, page, PAGE_SIZE, 0);
469 if (ret != PAGE_SIZE) {
470 pr_err("pblk: could not add page to bio\n");
472 bio = ERR_PTR(-ENOMEM);
482 int pblk_calc_secs(struct pblk *pblk, unsigned long secs_avail,
483 unsigned long secs_to_flush)
485 int max = pblk->sec_per_write;
486 int min = pblk->min_write_pgs;
487 int secs_to_sync = 0;
489 if (secs_avail >= max)
491 else if (secs_avail >= min)
492 secs_to_sync = min * (secs_avail / min);
493 else if (secs_to_flush)
499 static u64 __pblk_alloc_page(struct pblk *pblk, struct pblk_line *line,
505 /* logic error: ppa out-of-bounds. Prevent generating bad address */
506 if (line->cur_sec + nr_secs > pblk->lm.sec_per_line) {
507 WARN(1, "pblk: page allocation out of bounds\n");
508 nr_secs = pblk->lm.sec_per_line - line->cur_sec;
511 line->cur_sec = addr = find_next_zero_bit(line->map_bitmap,
512 pblk->lm.sec_per_line, line->cur_sec);
513 for (i = 0; i < nr_secs; i++, line->cur_sec++)
514 WARN_ON(test_and_set_bit(line->cur_sec, line->map_bitmap));
519 u64 pblk_alloc_page(struct pblk *pblk, struct pblk_line *line, int nr_secs)
523 /* Lock needed in case a write fails and a recovery needs to remap
524 * failed write buffer entries
526 spin_lock(&line->lock);
527 addr = __pblk_alloc_page(pblk, line, nr_secs);
528 line->left_msecs -= nr_secs;
529 WARN(line->left_msecs < 0, "pblk: page allocation out of bounds\n");
530 spin_unlock(&line->lock);
536 * Submit emeta to one LUN in the raid line at the time to avoid a deadlock when
537 * taking the per LUN semaphore.
539 static int pblk_line_submit_emeta_io(struct pblk *pblk, struct pblk_line *line,
542 struct nvm_tgt_dev *dev = pblk->dev;
543 struct nvm_geo *geo = &dev->geo;
544 struct pblk_line_meta *lm = &pblk->lm;
547 struct ppa_addr *ppa_list;
548 dma_addr_t dma_ppa_list;
549 void *emeta = line->emeta;
550 int min = pblk->min_write_pgs;
551 int left_ppas = lm->emeta_sec;
558 DECLARE_COMPLETION_ONSTACK(wait);
561 bio_op = REQ_OP_WRITE;
562 cmd_op = NVM_OP_PWRITE;
563 flags = pblk_set_progr_mode(pblk, WRITE);
564 } else if (dir == READ) {
565 bio_op = REQ_OP_READ;
566 cmd_op = NVM_OP_PREAD;
567 flags = pblk_set_read_mode(pblk);
571 ppa_list = nvm_dev_dma_alloc(dev->parent, GFP_KERNEL, &dma_ppa_list);
576 memset(&rqd, 0, sizeof(struct nvm_rq));
578 rq_ppas = pblk_calc_secs(pblk, left_ppas, 0);
579 rq_len = rq_ppas * geo->sec_size;
581 bio = pblk_bio_map_addr(pblk, emeta, rq_ppas, rq_len, GFP_KERNEL);
587 bio->bi_iter.bi_sector = 0; /* internal bio */
588 bio_set_op_attrs(bio, bio_op, 0);
593 rqd.nr_ppas = rq_ppas;
594 rqd.ppa_list = ppa_list;
595 rqd.dma_ppa_list = dma_ppa_list;
596 rqd.end_io = pblk_end_io_sync;
600 for (i = 0; i < rqd.nr_ppas; ) {
601 spin_lock(&line->lock);
602 paddr = __pblk_alloc_page(pblk, line, min);
603 spin_unlock(&line->lock);
604 for (j = 0; j < min; j++, i++, paddr++)
606 addr_to_gen_ppa(pblk, paddr, id);
609 for (i = 0; i < rqd.nr_ppas; ) {
610 struct ppa_addr ppa = addr_to_gen_ppa(pblk, paddr, id);
611 int pos = pblk_dev_ppa_to_pos(geo, ppa);
613 while (test_bit(pos, line->blk_bitmap)) {
615 if (pblk_boundary_paddr_checks(pblk, paddr)) {
616 pr_err("pblk: corrupt emeta line:%d\n",
623 ppa = addr_to_gen_ppa(pblk, paddr, id);
624 pos = pblk_dev_ppa_to_pos(geo, ppa);
627 if (pblk_boundary_paddr_checks(pblk, paddr + min)) {
628 pr_err("pblk: corrupt emeta line:%d\n",
635 for (j = 0; j < min; j++, i++, paddr++)
637 addr_to_gen_ppa(pblk, paddr, line->id);
641 ret = pblk_submit_io(pblk, &rqd);
643 pr_err("pblk: emeta I/O submission failed: %d\n", ret);
648 if (!wait_for_completion_io_timeout(&wait,
649 msecs_to_jiffies(PBLK_COMMAND_TIMEOUT_MS))) {
650 pr_err("pblk: emeta I/O timed out\n");
652 reinit_completion(&wait);
658 pblk_log_write_err(pblk, &rqd);
660 pblk_log_read_err(pblk, &rqd);
664 left_ppas -= rq_ppas;
668 nvm_dev_dma_free(dev->parent, ppa_list, dma_ppa_list);
672 u64 pblk_line_smeta_start(struct pblk *pblk, struct pblk_line *line)
674 struct nvm_tgt_dev *dev = pblk->dev;
675 struct nvm_geo *geo = &dev->geo;
676 struct pblk_line_meta *lm = &pblk->lm;
679 /* This usually only happens on bad lines */
680 bit = find_first_zero_bit(line->blk_bitmap, lm->blk_per_line);
681 if (bit >= lm->blk_per_line)
684 return bit * geo->sec_per_pl;
687 static int pblk_line_submit_smeta_io(struct pblk *pblk, struct pblk_line *line,
690 struct nvm_tgt_dev *dev = pblk->dev;
691 struct pblk_line_meta *lm = &pblk->lm;
694 __le64 *lba_list = NULL;
698 DECLARE_COMPLETION_ONSTACK(wait);
701 bio_op = REQ_OP_WRITE;
702 cmd_op = NVM_OP_PWRITE;
703 flags = pblk_set_progr_mode(pblk, WRITE);
704 lba_list = pblk_line_emeta_to_lbas(line->emeta);
705 } else if (dir == READ) {
706 bio_op = REQ_OP_READ;
707 cmd_op = NVM_OP_PREAD;
708 flags = pblk_set_read_mode(pblk);
712 memset(&rqd, 0, sizeof(struct nvm_rq));
714 rqd.ppa_list = nvm_dev_dma_alloc(dev->parent, GFP_KERNEL,
719 bio = bio_map_kern(dev->q, line->smeta, lm->smeta_len, GFP_KERNEL);
725 bio->bi_iter.bi_sector = 0; /* internal bio */
726 bio_set_op_attrs(bio, bio_op, 0);
731 rqd.nr_ppas = lm->smeta_sec;
732 rqd.end_io = pblk_end_io_sync;
735 for (i = 0; i < lm->smeta_sec; i++, paddr++) {
736 rqd.ppa_list[i] = addr_to_gen_ppa(pblk, paddr, line->id);
738 lba_list[paddr] = cpu_to_le64(ADDR_EMPTY);
742 * This I/O is sent by the write thread when a line is replace. Since
743 * the write thread is the only one sending write and erase commands,
744 * there is no need to take the LUN semaphore.
746 ret = pblk_submit_io(pblk, &rqd);
748 pr_err("pblk: smeta I/O submission failed: %d\n", ret);
753 if (!wait_for_completion_io_timeout(&wait,
754 msecs_to_jiffies(PBLK_COMMAND_TIMEOUT_MS))) {
755 pr_err("pblk: smeta I/O timed out\n");
760 pblk_log_write_err(pblk, &rqd);
762 pblk_log_read_err(pblk, &rqd);
766 nvm_dev_dma_free(dev->parent, rqd.ppa_list, rqd.dma_ppa_list);
771 int pblk_line_read_smeta(struct pblk *pblk, struct pblk_line *line)
773 u64 bpaddr = pblk_line_smeta_start(pblk, line);
775 return pblk_line_submit_smeta_io(pblk, line, bpaddr, READ);
778 int pblk_line_read_emeta(struct pblk *pblk, struct pblk_line *line)
780 return pblk_line_submit_emeta_io(pblk, line, line->emeta_ssec, READ);
783 static void pblk_setup_e_rq(struct pblk *pblk, struct nvm_rq *rqd,
786 rqd->opcode = NVM_OP_ERASE;
789 rqd->flags = pblk_set_progr_mode(pblk, ERASE);
793 static int pblk_blk_erase_sync(struct pblk *pblk, struct ppa_addr ppa)
797 DECLARE_COMPLETION_ONSTACK(wait);
799 memset(&rqd, 0, sizeof(struct nvm_rq));
801 pblk_setup_e_rq(pblk, &rqd, ppa);
803 rqd.end_io = pblk_end_io_sync;
806 /* The write thread schedules erases so that it minimizes disturbances
807 * with writes. Thus, there is no need to take the LUN semaphore.
809 ret = pblk_submit_io(pblk, &rqd);
811 struct nvm_tgt_dev *dev = pblk->dev;
812 struct nvm_geo *geo = &dev->geo;
814 pr_err("pblk: could not sync erase line:%d,blk:%d\n",
815 pblk_dev_ppa_to_line(ppa),
816 pblk_dev_ppa_to_pos(geo, ppa));
822 if (!wait_for_completion_io_timeout(&wait,
823 msecs_to_jiffies(PBLK_COMMAND_TIMEOUT_MS))) {
824 pr_err("pblk: sync erase timed out\n");
829 __pblk_end_io_erase(pblk, &rqd);
834 int pblk_line_erase(struct pblk *pblk, struct pblk_line *line)
836 struct pblk_line_meta *lm = &pblk->lm;
840 /* Erase only good blocks, one at a time */
842 spin_lock(&line->lock);
843 bit = find_next_zero_bit(line->erase_bitmap, lm->blk_per_line,
845 if (bit >= lm->blk_per_line) {
846 spin_unlock(&line->lock);
850 ppa = pblk->luns[bit].bppa; /* set ch and lun */
851 ppa.g.blk = line->id;
853 atomic_dec(&line->left_eblks);
854 WARN_ON(test_and_set_bit(bit, line->erase_bitmap));
855 spin_unlock(&line->lock);
857 if (pblk_blk_erase_sync(pblk, ppa)) {
858 pr_err("pblk: failed to erase line %d\n", line->id);
866 /* For now lines are always assumed full lines. Thus, smeta former and current
867 * lun bitmaps are omitted.
869 static int pblk_line_set_metadata(struct pblk *pblk, struct pblk_line *line,
870 struct pblk_line *cur)
872 struct nvm_tgt_dev *dev = pblk->dev;
873 struct nvm_geo *geo = &dev->geo;
874 struct pblk_line_meta *lm = &pblk->lm;
875 struct pblk_line_mgmt *l_mg = &pblk->l_mg;
876 struct line_smeta *smeta = line->smeta;
877 struct line_emeta *emeta = line->emeta;
880 /* After erasing the line, new bad blocks might appear and we risk
881 * having an invalid line
883 nr_blk_line = lm->blk_per_line -
884 bitmap_weight(line->blk_bitmap, lm->blk_per_line);
885 if (nr_blk_line < lm->min_blk_line) {
886 spin_lock(&l_mg->free_lock);
887 spin_lock(&line->lock);
888 line->state = PBLK_LINESTATE_BAD;
889 spin_unlock(&line->lock);
891 list_add_tail(&line->list, &l_mg->bad_list);
892 spin_unlock(&l_mg->free_lock);
894 pr_debug("pblk: line %d is bad\n", line->id);
899 /* Run-time metadata */
900 line->lun_bitmap = ((void *)(smeta)) + sizeof(struct line_smeta);
902 /* Mark LUNs allocated in this line (all for now) */
903 bitmap_set(line->lun_bitmap, 0, lm->lun_bitmap_len);
905 smeta->header.identifier = cpu_to_le32(PBLK_MAGIC);
906 memcpy(smeta->header.uuid, pblk->instance_uuid, 16);
907 smeta->header.id = cpu_to_le32(line->id);
908 smeta->header.type = cpu_to_le16(line->type);
909 smeta->header.version = cpu_to_le16(1);
912 smeta->seq_nr = cpu_to_le64(line->seq_nr);
913 smeta->window_wr_lun = cpu_to_le32(geo->nr_luns);
915 /* Fill metadata among lines */
917 memcpy(line->lun_bitmap, cur->lun_bitmap, lm->lun_bitmap_len);
918 smeta->prev_id = cpu_to_le32(cur->id);
919 cur->emeta->next_id = cpu_to_le32(line->id);
921 smeta->prev_id = cpu_to_le32(PBLK_LINE_EMPTY);
924 /* All smeta must be set at this point */
925 smeta->header.crc = cpu_to_le32(pblk_calc_meta_header_crc(pblk, smeta));
926 smeta->crc = cpu_to_le32(pblk_calc_smeta_crc(pblk, smeta));
929 memcpy(&emeta->header, &smeta->header, sizeof(struct line_header));
930 emeta->seq_nr = cpu_to_le64(line->seq_nr);
931 emeta->nr_lbas = cpu_to_le64(line->sec_in_line);
932 emeta->nr_valid_lbas = cpu_to_le64(0);
933 emeta->next_id = cpu_to_le32(PBLK_LINE_EMPTY);
934 emeta->crc = cpu_to_le32(0);
935 emeta->prev_id = smeta->prev_id;
940 /* For now lines are always assumed full lines. Thus, smeta former and current
941 * lun bitmaps are omitted.
943 static int pblk_line_init_bb(struct pblk *pblk, struct pblk_line *line,
946 struct nvm_tgt_dev *dev = pblk->dev;
947 struct nvm_geo *geo = &dev->geo;
948 struct pblk_line_meta *lm = &pblk->lm;
949 struct pblk_line_mgmt *l_mg = &pblk->l_mg;
954 line->sec_in_line = lm->sec_per_line;
956 /* Capture bad block information on line mapping bitmaps */
957 while ((bit = find_next_bit(line->blk_bitmap, lm->blk_per_line,
958 bit + 1)) < lm->blk_per_line) {
959 off = bit * geo->sec_per_pl;
960 bitmap_shift_left(l_mg->bb_aux, l_mg->bb_template, off,
962 bitmap_or(line->map_bitmap, line->map_bitmap, l_mg->bb_aux,
964 line->sec_in_line -= geo->sec_per_blk;
965 if (bit >= lm->emeta_bb)
969 /* Mark smeta metadata sectors as bad sectors */
970 bit = find_first_zero_bit(line->blk_bitmap, lm->blk_per_line);
971 off = bit * geo->sec_per_pl;
973 bitmap_set(line->map_bitmap, off, lm->smeta_sec);
974 line->sec_in_line -= lm->smeta_sec;
975 line->smeta_ssec = off;
976 line->cur_sec = off + lm->smeta_sec;
978 if (init && pblk_line_submit_smeta_io(pblk, line, off, WRITE)) {
979 pr_debug("pblk: line smeta I/O failed. Retry\n");
980 off += geo->sec_per_pl;
984 bitmap_copy(line->invalid_bitmap, line->map_bitmap, lm->sec_per_line);
986 /* Mark emeta metadata sectors as bad sectors. We need to consider bad
987 * blocks to make sure that there are enough sectors to store emeta
989 bit = lm->sec_per_line;
990 off = lm->sec_per_line - lm->emeta_sec;
991 bitmap_set(line->invalid_bitmap, off, lm->emeta_sec);
993 off -= geo->sec_per_pl;
994 if (!test_bit(off, line->invalid_bitmap)) {
995 bitmap_set(line->invalid_bitmap, off, geo->sec_per_pl);
1000 line->sec_in_line -= lm->emeta_sec;
1001 line->emeta_ssec = off;
1002 line->vsc = line->left_ssecs = line->left_msecs = line->sec_in_line;
1004 if (lm->sec_per_line - line->sec_in_line !=
1005 bitmap_weight(line->invalid_bitmap, lm->sec_per_line)) {
1006 spin_lock(&line->lock);
1007 line->state = PBLK_LINESTATE_BAD;
1008 spin_unlock(&line->lock);
1010 list_add_tail(&line->list, &l_mg->bad_list);
1011 pr_err("pblk: unexpected line %d is bad\n", line->id);
1019 static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line)
1021 struct pblk_line_meta *lm = &pblk->lm;
1022 int blk_in_line = atomic_read(&line->blk_in_line);
1024 line->map_bitmap = mempool_alloc(pblk->line_meta_pool, GFP_ATOMIC);
1025 if (!line->map_bitmap)
1027 memset(line->map_bitmap, 0, lm->sec_bitmap_len);
1029 /* invalid_bitmap is special since it is used when line is closed. No
1030 * need to zeroized; it will be initialized using bb info form
1033 line->invalid_bitmap = mempool_alloc(pblk->line_meta_pool, GFP_ATOMIC);
1034 if (!line->invalid_bitmap) {
1035 mempool_free(line->map_bitmap, pblk->line_meta_pool);
1039 spin_lock(&line->lock);
1040 if (line->state != PBLK_LINESTATE_FREE) {
1041 spin_unlock(&line->lock);
1042 WARN(1, "pblk: corrupted line state\n");
1045 line->state = PBLK_LINESTATE_OPEN;
1047 atomic_set(&line->left_eblks, blk_in_line);
1048 atomic_set(&line->left_seblks, blk_in_line);
1049 spin_unlock(&line->lock);
1051 /* Bad blocks do not need to be erased */
1052 bitmap_copy(line->erase_bitmap, line->blk_bitmap, lm->blk_per_line);
1054 kref_init(&line->ref);
1059 int pblk_line_recov_alloc(struct pblk *pblk, struct pblk_line *line)
1061 struct pblk_line_mgmt *l_mg = &pblk->l_mg;
1064 spin_lock(&l_mg->free_lock);
1065 l_mg->data_line = line;
1066 list_del(&line->list);
1068 ret = pblk_line_prepare(pblk, line);
1070 list_add(&line->list, &l_mg->free_list);
1071 spin_unlock(&l_mg->free_lock);
1074 spin_unlock(&l_mg->free_lock);
1076 pblk_rl_free_lines_dec(&pblk->rl, line);
1078 if (!pblk_line_init_bb(pblk, line, 0)) {
1079 list_add(&line->list, &l_mg->free_list);
1086 void pblk_line_recov_close(struct pblk *pblk, struct pblk_line *line)
1088 mempool_free(line->map_bitmap, pblk->line_meta_pool);
1089 line->map_bitmap = NULL;
1094 struct pblk_line *pblk_line_get(struct pblk *pblk)
1096 struct pblk_line_mgmt *l_mg = &pblk->l_mg;
1097 struct pblk_line_meta *lm = &pblk->lm;
1098 struct pblk_line *line = NULL;
1101 lockdep_assert_held(&l_mg->free_lock);
1104 if (list_empty(&l_mg->free_list)) {
1105 pr_err("pblk: no free lines\n");
1109 line = list_first_entry(&l_mg->free_list, struct pblk_line, list);
1110 list_del(&line->list);
1111 l_mg->nr_free_lines--;
1113 bit = find_first_zero_bit(line->blk_bitmap, lm->blk_per_line);
1114 if (unlikely(bit >= lm->blk_per_line)) {
1115 spin_lock(&line->lock);
1116 line->state = PBLK_LINESTATE_BAD;
1117 spin_unlock(&line->lock);
1119 list_add_tail(&line->list, &l_mg->bad_list);
1121 pr_debug("pblk: line %d is bad\n", line->id);
1125 if (pblk_line_prepare(pblk, line)) {
1126 pr_err("pblk: failed to prepare line %d\n", line->id);
1127 list_add(&line->list, &l_mg->free_list);
1135 static struct pblk_line *pblk_line_retry(struct pblk *pblk,
1136 struct pblk_line *line)
1138 struct pblk_line_mgmt *l_mg = &pblk->l_mg;
1139 struct pblk_line *retry_line;
1141 spin_lock(&l_mg->free_lock);
1142 retry_line = pblk_line_get(pblk);
1144 l_mg->data_line = NULL;
1145 spin_unlock(&l_mg->free_lock);
1149 retry_line->smeta = line->smeta;
1150 retry_line->emeta = line->emeta;
1151 retry_line->meta_line = line->meta_line;
1153 pblk_line_free(pblk, line);
1154 l_mg->data_line = retry_line;
1155 spin_unlock(&l_mg->free_lock);
1157 if (pblk_line_erase(pblk, retry_line)) {
1158 spin_lock(&l_mg->free_lock);
1159 l_mg->data_line = NULL;
1160 spin_unlock(&l_mg->free_lock);
1164 pblk_rl_free_lines_dec(&pblk->rl, retry_line);
1169 struct pblk_line *pblk_line_get_first_data(struct pblk *pblk)
1171 struct pblk_line_mgmt *l_mg = &pblk->l_mg;
1172 struct pblk_line *line;
1176 spin_lock(&l_mg->free_lock);
1177 line = pblk_line_get(pblk);
1179 spin_unlock(&l_mg->free_lock);
1183 line->seq_nr = l_mg->d_seq_nr++;
1184 line->type = PBLK_LINETYPE_DATA;
1185 l_mg->data_line = line;
1187 meta_line = find_first_zero_bit(&l_mg->meta_bitmap, PBLK_DATA_LINES);
1188 set_bit(meta_line, &l_mg->meta_bitmap);
1189 line->smeta = l_mg->sline_meta[meta_line].meta;
1190 line->emeta = l_mg->eline_meta[meta_line].meta;
1191 line->meta_line = meta_line;
1193 /* Allocate next line for preparation */
1194 l_mg->data_next = pblk_line_get(pblk);
1195 if (l_mg->data_next) {
1196 l_mg->data_next->seq_nr = l_mg->d_seq_nr++;
1197 l_mg->data_next->type = PBLK_LINETYPE_DATA;
1200 spin_unlock(&l_mg->free_lock);
1202 pblk_rl_free_lines_dec(&pblk->rl, line);
1204 pblk_rl_free_lines_dec(&pblk->rl, l_mg->data_next);
1206 if (pblk_line_erase(pblk, line))
1210 if (!pblk_line_set_metadata(pblk, line, NULL)) {
1211 line = pblk_line_retry(pblk, line);
1218 if (!pblk_line_init_bb(pblk, line, 1)) {
1219 line = pblk_line_retry(pblk, line);
1229 struct pblk_line *pblk_line_replace_data(struct pblk *pblk)
1231 struct pblk_line_meta *lm = &pblk->lm;
1232 struct pblk_line_mgmt *l_mg = &pblk->l_mg;
1233 struct pblk_line *cur, *new;
1234 unsigned int left_seblks;
1238 cur = l_mg->data_line;
1239 new = l_mg->data_next;
1242 l_mg->data_line = new;
1245 left_seblks = atomic_read(&new->left_seblks);
1247 /* If line is not fully erased, erase it */
1248 if (atomic_read(&new->left_eblks)) {
1249 if (pblk_line_erase(pblk, new))
1257 spin_lock(&l_mg->free_lock);
1258 /* Allocate next line for preparation */
1259 l_mg->data_next = pblk_line_get(pblk);
1260 if (l_mg->data_next) {
1261 l_mg->data_next->seq_nr = l_mg->d_seq_nr++;
1262 l_mg->data_next->type = PBLK_LINETYPE_DATA;
1267 meta_line = find_first_zero_bit(&l_mg->meta_bitmap, PBLK_DATA_LINES);
1268 if (meta_line == PBLK_DATA_LINES) {
1269 spin_unlock(&l_mg->free_lock);
1271 spin_lock(&l_mg->free_lock);
1275 set_bit(meta_line, &l_mg->meta_bitmap);
1276 new->smeta = l_mg->sline_meta[meta_line].meta;
1277 new->emeta = l_mg->eline_meta[meta_line].meta;
1278 new->meta_line = meta_line;
1280 memset(new->smeta, 0, lm->smeta_len);
1281 memset(new->emeta, 0, lm->emeta_len);
1282 spin_unlock(&l_mg->free_lock);
1285 pblk_rl_free_lines_dec(&pblk->rl, l_mg->data_next);
1288 if (!pblk_line_set_metadata(pblk, new, cur)) {
1289 new = pblk_line_retry(pblk, new);
1296 if (!pblk_line_init_bb(pblk, new, 1)) {
1297 new = pblk_line_retry(pblk, new);
1307 void pblk_line_free(struct pblk *pblk, struct pblk_line *line)
1309 if (line->map_bitmap)
1310 mempool_free(line->map_bitmap, pblk->line_meta_pool);
1311 if (line->invalid_bitmap)
1312 mempool_free(line->invalid_bitmap, pblk->line_meta_pool);
1314 line->map_bitmap = NULL;
1315 line->invalid_bitmap = NULL;
1320 void pblk_line_put(struct kref *ref)
1322 struct pblk_line *line = container_of(ref, struct pblk_line, ref);
1323 struct pblk *pblk = line->pblk;
1324 struct pblk_line_mgmt *l_mg = &pblk->l_mg;
1326 spin_lock(&line->lock);
1327 WARN_ON(line->state != PBLK_LINESTATE_GC);
1328 line->state = PBLK_LINESTATE_FREE;
1329 line->gc_group = PBLK_LINEGC_NONE;
1330 pblk_line_free(pblk, line);
1331 spin_unlock(&line->lock);
1333 spin_lock(&l_mg->free_lock);
1334 list_add_tail(&line->list, &l_mg->free_list);
1335 l_mg->nr_free_lines++;
1336 spin_unlock(&l_mg->free_lock);
1338 pblk_rl_free_lines_inc(&pblk->rl, line);
1341 int pblk_blk_erase_async(struct pblk *pblk, struct ppa_addr ppa)
1346 rqd = mempool_alloc(pblk->r_rq_pool, GFP_KERNEL);
1347 memset(rqd, 0, pblk_r_rq_size);
1349 pblk_setup_e_rq(pblk, rqd, ppa);
1351 rqd->end_io = pblk_end_io_erase;
1352 rqd->private = pblk;
1354 /* The write thread schedules erases so that it minimizes disturbances
1355 * with writes. Thus, there is no need to take the LUN semaphore.
1357 err = pblk_submit_io(pblk, rqd);
1359 struct nvm_tgt_dev *dev = pblk->dev;
1360 struct nvm_geo *geo = &dev->geo;
1362 pr_err("pblk: could not async erase line:%d,blk:%d\n",
1363 pblk_dev_ppa_to_line(ppa),
1364 pblk_dev_ppa_to_pos(geo, ppa));
1370 struct pblk_line *pblk_line_get_data(struct pblk *pblk)
1372 return pblk->l_mg.data_line;
1375 /* For now, always erase next line */
1376 struct pblk_line *pblk_line_get_erase(struct pblk *pblk)
1378 return pblk->l_mg.data_next;
1381 int pblk_line_is_full(struct pblk_line *line)
1383 return (line->left_msecs == 0);
1386 void pblk_line_close(struct pblk *pblk, struct pblk_line *line)
1388 struct pblk_line_mgmt *l_mg = &pblk->l_mg;
1389 struct list_head *move_list;
1391 line->emeta->crc = cpu_to_le32(pblk_calc_emeta_crc(pblk, line->emeta));
1393 if (pblk_line_submit_emeta_io(pblk, line, line->cur_sec, WRITE))
1394 pr_err("pblk: line %d close I/O failed\n", line->id);
1396 WARN(!bitmap_full(line->map_bitmap, line->sec_in_line),
1397 "pblk: corrupt closed line %d\n", line->id);
1399 spin_lock(&l_mg->free_lock);
1400 WARN_ON(!test_and_clear_bit(line->meta_line, &l_mg->meta_bitmap));
1401 spin_unlock(&l_mg->free_lock);
1403 spin_lock(&l_mg->gc_lock);
1404 spin_lock(&line->lock);
1405 WARN_ON(line->state != PBLK_LINESTATE_OPEN);
1406 line->state = PBLK_LINESTATE_CLOSED;
1407 move_list = pblk_line_gc_list(pblk, line);
1409 list_add_tail(&line->list, move_list);
1411 mempool_free(line->map_bitmap, pblk->line_meta_pool);
1412 line->map_bitmap = NULL;
1416 spin_unlock(&line->lock);
1417 spin_unlock(&l_mg->gc_lock);
1420 void pblk_line_close_ws(struct work_struct *work)
1422 struct pblk_line_ws *line_ws = container_of(work, struct pblk_line_ws,
1424 struct pblk *pblk = line_ws->pblk;
1425 struct pblk_line *line = line_ws->line;
1427 pblk_line_close(pblk, line);
1428 mempool_free(line_ws, pblk->line_ws_pool);
1431 void pblk_line_mark_bb(struct work_struct *work)
1433 struct pblk_line_ws *line_ws = container_of(work, struct pblk_line_ws,
1435 struct pblk *pblk = line_ws->pblk;
1436 struct nvm_tgt_dev *dev = pblk->dev;
1437 struct ppa_addr *ppa = line_ws->priv;
1440 ret = nvm_set_tgt_bb_tbl(dev, ppa, 1, NVM_BLK_T_GRWN_BAD);
1442 struct pblk_line *line;
1445 line = &pblk->lines[pblk_dev_ppa_to_line(*ppa)];
1446 pos = pblk_dev_ppa_to_pos(&dev->geo, *ppa);
1448 pr_err("pblk: failed to mark bb, line:%d, pos:%d\n",
1453 mempool_free(line_ws, pblk->line_ws_pool);
1456 void pblk_line_run_ws(struct pblk *pblk, struct pblk_line *line, void *priv,
1457 void (*work)(struct work_struct *))
1459 struct pblk_line_ws *line_ws;
1461 line_ws = mempool_alloc(pblk->line_ws_pool, GFP_ATOMIC);
1465 line_ws->pblk = pblk;
1466 line_ws->line = line;
1467 line_ws->priv = priv;
1469 INIT_WORK(&line_ws->ws, work);
1470 queue_work(pblk->kw_wq, &line_ws->ws);
1473 void pblk_down_rq(struct pblk *pblk, struct ppa_addr *ppa_list, int nr_ppas,
1474 unsigned long *lun_bitmap)
1476 struct nvm_tgt_dev *dev = pblk->dev;
1477 struct nvm_geo *geo = &dev->geo;
1478 struct pblk_lun *rlun;
1479 int lun_id = ppa_list[0].g.ch * geo->luns_per_chnl + ppa_list[0].g.lun;
1483 * Only send one inflight I/O per LUN. Since we map at a page
1484 * granurality, all ppas in the I/O will map to the same LUN
1486 #ifdef CONFIG_NVM_DEBUG
1489 for (i = 1; i < nr_ppas; i++)
1490 WARN_ON(ppa_list[0].g.lun != ppa_list[i].g.lun ||
1491 ppa_list[0].g.ch != ppa_list[i].g.ch);
1493 /* If the LUN has been locked for this same request, do no attempt to
1496 if (test_and_set_bit(lun_id, lun_bitmap))
1499 rlun = &pblk->luns[lun_id];
1500 ret = down_timeout(&rlun->wr_sem, msecs_to_jiffies(5000));
1504 pr_err("pblk: lun semaphore timed out\n");
1507 pr_err("pblk: lun semaphore timed out\n");
1513 void pblk_up_rq(struct pblk *pblk, struct ppa_addr *ppa_list, int nr_ppas,
1514 unsigned long *lun_bitmap)
1516 struct nvm_tgt_dev *dev = pblk->dev;
1517 struct nvm_geo *geo = &dev->geo;
1518 struct pblk_lun *rlun;
1519 int nr_luns = geo->nr_luns;
1522 while ((bit = find_next_bit(lun_bitmap, nr_luns, bit + 1)) < nr_luns) {
1523 rlun = &pblk->luns[bit];
1530 void pblk_update_map(struct pblk *pblk, sector_t lba, struct ppa_addr ppa)
1532 struct ppa_addr l2p_ppa;
1534 /* logic error: lba out-of-bounds. Ignore update */
1535 if (!(lba < pblk->rl.nr_secs)) {
1536 WARN(1, "pblk: corrupted L2P map request\n");
1540 spin_lock(&pblk->trans_lock);
1541 l2p_ppa = pblk_trans_map_get(pblk, lba);
1543 if (!pblk_addr_in_cache(l2p_ppa) && !pblk_ppa_empty(l2p_ppa))
1544 pblk_map_invalidate(pblk, l2p_ppa);
1546 pblk_trans_map_set(pblk, lba, ppa);
1547 spin_unlock(&pblk->trans_lock);
1550 void pblk_update_map_cache(struct pblk *pblk, sector_t lba, struct ppa_addr ppa)
1552 #ifdef CONFIG_NVM_DEBUG
1553 /* Callers must ensure that the ppa points to a cache address */
1554 BUG_ON(!pblk_addr_in_cache(ppa));
1555 BUG_ON(pblk_rb_pos_oob(&pblk->rwb, pblk_addr_to_cacheline(ppa)));
1558 pblk_update_map(pblk, lba, ppa);
1561 int pblk_update_map_gc(struct pblk *pblk, sector_t lba, struct ppa_addr ppa,
1562 struct pblk_line *gc_line)
1564 struct ppa_addr l2p_ppa;
1567 #ifdef CONFIG_NVM_DEBUG
1568 /* Callers must ensure that the ppa points to a cache address */
1569 BUG_ON(!pblk_addr_in_cache(ppa));
1570 BUG_ON(pblk_rb_pos_oob(&pblk->rwb, pblk_addr_to_cacheline(ppa)));
1573 /* logic error: lba out-of-bounds. Ignore update */
1574 if (!(lba < pblk->rl.nr_secs)) {
1575 WARN(1, "pblk: corrupted L2P map request\n");
1579 spin_lock(&pblk->trans_lock);
1580 l2p_ppa = pblk_trans_map_get(pblk, lba);
1582 /* Prevent updated entries to be overwritten by GC */
1583 if (pblk_addr_in_cache(l2p_ppa) || pblk_ppa_empty(l2p_ppa) ||
1584 pblk_tgt_ppa_to_line(l2p_ppa) != gc_line->id) {
1589 pblk_trans_map_set(pblk, lba, ppa);
1591 spin_unlock(&pblk->trans_lock);
1595 void pblk_update_map_dev(struct pblk *pblk, sector_t lba, struct ppa_addr ppa,
1596 struct ppa_addr entry_line)
1598 struct ppa_addr l2p_line;
1600 #ifdef CONFIG_NVM_DEBUG
1601 /* Callers must ensure that the ppa points to a device address */
1602 BUG_ON(pblk_addr_in_cache(ppa));
1604 /* Invalidate and discard padded entries */
1605 if (lba == ADDR_EMPTY) {
1606 #ifdef CONFIG_NVM_DEBUG
1607 atomic_long_inc(&pblk->padded_wb);
1609 pblk_map_invalidate(pblk, ppa);
1613 /* logic error: lba out-of-bounds. Ignore update */
1614 if (!(lba < pblk->rl.nr_secs)) {
1615 WARN(1, "pblk: corrupted L2P map request\n");
1619 spin_lock(&pblk->trans_lock);
1620 l2p_line = pblk_trans_map_get(pblk, lba);
1622 /* Do not update L2P if the cacheline has been updated. In this case,
1623 * the mapped ppa must be invalidated
1625 if (l2p_line.ppa != entry_line.ppa) {
1626 if (!pblk_ppa_empty(ppa))
1627 pblk_map_invalidate(pblk, ppa);
1631 #ifdef CONFIG_NVM_DEBUG
1632 WARN_ON(!pblk_addr_in_cache(l2p_line) && !pblk_ppa_empty(l2p_line));
1635 pblk_trans_map_set(pblk, lba, ppa);
1637 spin_unlock(&pblk->trans_lock);
1640 void pblk_lookup_l2p_seq(struct pblk *pblk, struct ppa_addr *ppas,
1641 sector_t blba, int nr_secs)
1645 spin_lock(&pblk->trans_lock);
1646 for (i = 0; i < nr_secs; i++)
1647 ppas[i] = pblk_trans_map_get(pblk, blba + i);
1648 spin_unlock(&pblk->trans_lock);
1651 void pblk_lookup_l2p_rand(struct pblk *pblk, struct ppa_addr *ppas,
1652 u64 *lba_list, int nr_secs)
1657 spin_lock(&pblk->trans_lock);
1658 for (i = 0; i < nr_secs; i++) {
1660 if (lba == ADDR_EMPTY) {
1661 ppas[i].ppa = ADDR_EMPTY;
1663 /* logic error: lba out-of-bounds. Ignore update */
1664 if (!(lba < pblk->rl.nr_secs)) {
1665 WARN(1, "pblk: corrupted L2P map request\n");
1668 ppas[i] = pblk_trans_map_get(pblk, lba);
1671 spin_unlock(&pblk->trans_lock);