mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Matias Bjørling" <m@bjorling.me>
To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@fb.com
Cc: "Matias Bjørling" <m@bjorling.me>
Subject: [PATCH 13/28] lightnvm: remove struct factory_blks
Date: Fri,  6 May 2016 20:03:06 +0200	[thread overview]
Message-ID: <1462557801-24974-14-git-send-email-m@bjorling.me> (raw)
In-Reply-To: <1462557801-24974-1-git-send-email-m@bjorling.me>

Now that device ops->get_bb_table no longer uses a callback, the
struct factory_blks can be removed.

Signed-off-by: Matias Bjørling <m@bjorling.me>
---
 drivers/lightnvm/sysblk.c | 62 +++++++++++++++++++++--------------------------
 1 file changed, 28 insertions(+), 34 deletions(-)

diff --git a/drivers/lightnvm/sysblk.c b/drivers/lightnvm/sysblk.c
index dc99c0a..bca6902 100644
--- a/drivers/lightnvm/sysblk.c
+++ b/drivers/lightnvm/sysblk.c
@@ -582,29 +582,23 @@ err_mark:
 	return ret;
 }
 
-struct factory_blks {
-	struct nvm_dev *dev;
-	int flags;
-	unsigned long *blks;
-};
-
 static int factory_nblks(int nblks)
 {
 	/* Round up to nearest BITS_PER_LONG */
 	return (nblks + (BITS_PER_LONG - 1)) & ~(BITS_PER_LONG - 1);
 }
 
-static unsigned int factory_blk_offset(struct nvm_dev *dev, int ch, int lun)
+static unsigned int factory_blk_offset(struct nvm_dev *dev, struct ppa_addr ppa)
 {
 	int nblks = factory_nblks(dev->blks_per_lun);
 
-	return ((ch * dev->luns_per_chnl * nblks) + (lun * nblks)) /
+	return ((ppa.g.ch * dev->luns_per_chnl * nblks) + (ppa.g.lun * nblks)) /
 								BITS_PER_LONG;
 }
 
 static int nvm_factory_blks(struct nvm_dev *dev, struct ppa_addr ppa,
 					u8 *blks, int nr_blks,
-					struct factory_blks *f)
+					unsigned long *blk_bitmap, int flags)
 {
 	int i, lunoff;
 
@@ -612,25 +606,25 @@ static int nvm_factory_blks(struct nvm_dev *dev, struct ppa_addr ppa,
 	if (nr_blks < 0)
 		return nr_blks;
 
-	lunoff = factory_blk_offset(dev, ppa.g.ch, ppa.g.lun);
+	lunoff = factory_blk_offset(dev, ppa);
 
 	/* non-set bits correspond to the block must be erased */
 	for (i = 0; i < nr_blks; i++) {
 		switch (blks[i]) {
 		case NVM_BLK_T_FREE:
-			if (f->flags & NVM_FACTORY_ERASE_ONLY_USER)
-				set_bit(i, &f->blks[lunoff]);
+			if (flags & NVM_FACTORY_ERASE_ONLY_USER)
+				set_bit(i, &blk_bitmap[lunoff]);
 			break;
 		case NVM_BLK_T_HOST:
-			if (!(f->flags & NVM_FACTORY_RESET_HOST_BLKS))
-				set_bit(i, &f->blks[lunoff]);
+			if (!(flags & NVM_FACTORY_RESET_HOST_BLKS))
+				set_bit(i, &blk_bitmap[lunoff]);
 			break;
 		case NVM_BLK_T_GRWN_BAD:
-			if (!(f->flags & NVM_FACTORY_RESET_GRWN_BBLKS))
-				set_bit(i, &f->blks[lunoff]);
+			if (!(flags & NVM_FACTORY_RESET_GRWN_BBLKS))
+				set_bit(i, &blk_bitmap[lunoff]);
 			break;
 		default:
-			set_bit(i, &f->blks[lunoff]);
+			set_bit(i, &blk_bitmap[lunoff]);
 			break;
 		}
 	}
@@ -639,7 +633,7 @@ static int nvm_factory_blks(struct nvm_dev *dev, struct ppa_addr ppa,
 }
 
 static int nvm_fact_get_blks(struct nvm_dev *dev, struct ppa_addr *erase_list,
-					int max_ppas, struct factory_blks *f)
+					int max_ppas, unsigned long *blk_bitmap)
 {
 	struct ppa_addr ppa;
 	int ch, lun, blkid, idx, done = 0, ppa_cnt = 0;
@@ -648,8 +642,8 @@ static int nvm_fact_get_blks(struct nvm_dev *dev, struct ppa_addr *erase_list,
 	while (!done) {
 		done = 1;
 		nvm_for_each_lun_ppa(dev, ppa, ch, lun) {
-			idx = factory_blk_offset(dev, ch, lun);
-			offset = &f->blks[idx];
+			idx = factory_blk_offset(dev, ppa);
+			offset = &blk_bitmap[idx];
 
 			blkid = find_first_zero_bit(offset,
 						dev->blks_per_lun);
@@ -675,10 +669,11 @@ static int nvm_fact_get_blks(struct nvm_dev *dev, struct ppa_addr *erase_list,
 	return ppa_cnt;
 }
 
-static int nvm_fact_select_blks(struct nvm_dev *dev, struct factory_blks *f)
+static int nvm_fact_select_blks(struct nvm_dev *dev, unsigned long *blk_bitmap,
+								int flags)
 {
 	struct ppa_addr ppa;
-	int ch, lun, nr_blks, ret;
+	int ch, lun, nr_blks, ret = 0;
 	u8 *blks;
 
 	nr_blks = dev->blks_per_lun * dev->plane_mode;
@@ -692,43 +687,42 @@ static int nvm_fact_select_blks(struct nvm_dev *dev, struct factory_blks *f)
 			pr_err("nvm: failed bb tbl for ch%u lun%u\n",
 							ppa.g.ch, ppa.g.blk);
 
-		ret = nvm_factory_blks(dev, ppa, blks, nr_blks, f);
+		ret = nvm_factory_blks(dev, ppa, blks, nr_blks, blk_bitmap,
+									flags);
 		if (ret)
-			return ret;
+			break;
 	}
 
 	kfree(blks);
-	return 0;
+	return ret;
 }
 
 int nvm_dev_factory(struct nvm_dev *dev, int flags)
 {
-	struct factory_blks f;
 	struct ppa_addr *ppas;
 	int ppa_cnt, ret = -ENOMEM;
 	int max_ppas = dev->ops->max_phys_sect / dev->nr_planes;
 	struct ppa_addr sysblk_ppas[MAX_SYSBLKS];
 	struct sysblk_scan s;
+	unsigned long *blk_bitmap;
 
-	f.blks = kzalloc(factory_nblks(dev->blks_per_lun) * dev->nr_luns,
+	blk_bitmap = kzalloc(factory_nblks(dev->blks_per_lun) * dev->nr_luns,
 								GFP_KERNEL);
-	if (!f.blks)
+	if (!blk_bitmap)
 		return ret;
 
 	ppas = kcalloc(max_ppas, sizeof(struct ppa_addr), GFP_KERNEL);
 	if (!ppas)
 		goto err_blks;
 
-	f.dev = dev;
-	f.flags = flags;
-
 	/* create list of blks to be erased */
-	ret = nvm_fact_select_blks(dev, &f);
+	ret = nvm_fact_select_blks(dev, blk_bitmap, flags);
 	if (ret)
 		goto err_ppas;
 
 	/* continue to erase until list of blks until empty */
-	while ((ppa_cnt = nvm_fact_get_blks(dev, ppas, max_ppas, &f)) > 0)
+	while ((ppa_cnt =
+			nvm_fact_get_blks(dev, ppas, max_ppas, blk_bitmap)) > 0)
 		nvm_erase_ppa(dev, ppas, ppa_cnt);
 
 	/* mark host reserved blocks free */
@@ -743,7 +737,7 @@ int nvm_dev_factory(struct nvm_dev *dev, int flags)
 err_ppas:
 	kfree(ppas);
 err_blks:
-	kfree(f.blks);
+	kfree(blk_bitmap);
 	return ret;
 }
 EXPORT_SYMBOL(nvm_dev_factory);
-- 
2.1.4

  parent reply	other threads:[~2016-05-06 18:11 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-06 18:02 [PATCH 00/28] LightNVM fixes for 4.7 Matias Bjørling
2016-05-06 18:02 ` [PATCH 01/28] lightnvm: fix "warning: ‘ret’ may be used uninitialized" Matias Bjørling
2016-05-06 18:02 ` [PATCH 02/28] lightnvm: handle submit_io failure Matias Bjørling
2016-05-06 18:02 ` [PATCH 03/28] lightnvm: implement nvm_submit_ppa_list Matias Bjørling
2016-05-06 18:02 ` [PATCH 04/28] lightnvm: add fpg_size and pfpg_size to struct nvm_dev Matias Bjørling
2016-05-06 18:02 ` [PATCH 05/28] lightnvm: move block fold outside of get_bb_tbl() Matias Bjørling
2016-05-06 18:02 ` [PATCH 06/28] lightnvm: avoid memory leak when lun_map kcalloc fails Matias Bjørling
2016-05-06 18:03 ` [PATCH 07/28] lightnvm: calculate rrpc total blocks and sectors up front Matias Bjørling
2016-05-06 18:03 ` [PATCH 08/28] lightnvm: store rrpc->soffset in device sector size Matias Bjørling
2016-05-06 18:03 ` [PATCH 09/28] lightnvm: rename nvm_targets to nvm_tgt_type Matias Bjørling
2016-05-06 18:03 ` [PATCH 10/28] lightnvm: refactor dev->online_target to global nvm_targets Matias Bjørling
2016-05-06 18:03 ` [PATCH 11/28] lightnvm: introduce nvm_for_each_lun_ppa() macro Matias Bjørling
2016-05-06 18:03 ` [PATCH 12/28] lightnvm: refactor device ops->get_bb_tbl() Matias Bjørling
2016-05-06 18:03 ` Matias Bjørling [this message]
2016-05-06 18:03 ` [PATCH 14/28] lightnvm: make nvm_set_rqd_ppalist() aware of vblks Matias Bjørling
2016-05-06 18:03 ` [PATCH 15/28] lightnvm: move responsibility for bad blk mgmt to target Matias Bjørling
2016-05-06 18:03 ` [PATCH 16/28] lightnvm: refactor set_bb_tbl for accepting ppa list Matias Bjørling
2016-05-06 18:03 ` [PATCH 17/28] lightnvm: fix out of bound ppa lun id on bb tbl Matias Bjørling
2016-05-06 18:03 ` [PATCH 18/28] lightnvm: do not free unused metadata on rrpc Matias Bjørling
2016-05-06 18:03 ` [PATCH 19/28] lightnvm: enable metadata to be sent to device Matias Bjørling
2016-05-06 18:03 ` [PATCH 20/28] lightnvm: rename dma helper functions Matias Bjørling
2016-05-06 18:03 ` [PATCH 21/28] nvme/lightnvm: Log using the ctrl named device Matias Bjørling
2016-05-06 18:03 ` [PATCH 22/28] lightnvm: do not assume sequential lun alloc Matias Bjørling
2016-05-06 18:03 ` [PATCH 23/28] lightnvm: pass dma address to hardware rather than pointer Matias Bjørling
2016-05-06 18:03 ` [PATCH 24/28] lightnvm: remove mgt targets on mgt removal Matias Bjørling
2016-05-06 18:03 ` [PATCH 25/28] lightnvm: expose gennvm_mark_blk to targets Matias Bjørling
2016-05-06 18:03 ` [PATCH 26/28] lightnvm: add is_cached entry to struct ppa_addr Matias Bjørling
2016-05-06 18:03 ` [PATCH 27/28] lightnvm: rename nr_pages to nr_ppas on nvm_rq Matias Bjørling
2016-05-06 18:03 ` [PATCH 28/28] lightnvm: reserved space calculation incorrect Matias Bjørling
2016-05-10 14:43 ` [PATCH 00/28] LightNVM fixes for 4.7 Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462557801-24974-14-git-send-email-m@bjorling.me \
    --to=m@bjorling.me \
    --cc=axboe@fb.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®