All of lore.kernel.org
 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 04/28] lightnvm: add fpg_size and pfpg_size to struct nvm_dev
Date: Fri,  6 May 2016 20:02:57 +0200	[thread overview]
Message-ID: <1462557801-24974-5-git-send-email-m@bjorling.me> (raw)
In-Reply-To: <1462557801-24974-1-git-send-email-m@bjorling.me>

The flash page size (fpg) and size across planes (pfpg) are convenient
to know when allocating buffer sizes. This has previously been a
calculated in various places. Replace with the pre-calculated values.

Reviewed by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Matias Bjørling <m@bjorling.me>
---
 drivers/lightnvm/core.c   |  2 ++
 drivers/lightnvm/sysblk.c | 17 +++++++----------
 include/linux/lightnvm.h  |  2 ++
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index f4e04a5..652b8c7 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -476,6 +476,8 @@ static int nvm_core_init(struct nvm_dev *dev)
 	dev->pgs_per_blk = grp->num_pg;
 	dev->blks_per_lun = grp->num_blk;
 	dev->nr_planes = grp->num_pln;
+	dev->fpg_size = grp->fpg_sz;
+	dev->pfpg_size = grp->fpg_sz * grp->num_pln;
 	dev->sec_size = grp->csecs;
 	dev->oob_size = grp->sos;
 	dev->sec_per_pg = grp->fpg_sz / grp->csecs;
diff --git a/drivers/lightnvm/sysblk.c b/drivers/lightnvm/sysblk.c
index b1e1404..b6971f8 100644
--- a/drivers/lightnvm/sysblk.c
+++ b/drivers/lightnvm/sysblk.c
@@ -154,13 +154,12 @@ static int nvm_scan_block(struct nvm_dev *dev, struct ppa_addr *ppa,
 						struct nvm_system_block *sblk)
 {
 	struct nvm_system_block *cur;
-	int pg, cursz, ret, found = 0;
+	int pg, ret, found = 0;
 
 	/* the full buffer for a flash page is allocated. Only the first of it
 	 * contains the system block information
 	 */
-	cursz = dev->sec_size * dev->sec_per_pg * dev->nr_planes;
-	cur = kmalloc(cursz, GFP_KERNEL);
+	cur = kmalloc(dev->pfpg_size, GFP_KERNEL);
 	if (!cur)
 		return -ENOMEM;
 
@@ -169,7 +168,7 @@ static int nvm_scan_block(struct nvm_dev *dev, struct ppa_addr *ppa,
 		ppa->g.pg = ppa_to_slc(dev, pg);
 
 		ret = nvm_submit_ppa(dev, ppa, 1, NVM_OP_PREAD, NVM_IO_SLC_MODE,
-								cur, cursz);
+							cur, dev->pfpg_size);
 		if (ret) {
 			if (ret == NVM_RSP_ERR_EMPTYPAGE) {
 				pr_debug("nvm: sysblk scan empty ppa (%u %u %u %u)\n",
@@ -272,14 +271,12 @@ static int nvm_write_and_verify(struct nvm_dev *dev, struct nvm_sb_info *info,
 {
 	struct nvm_system_block nvmsb;
 	void *buf;
-	int i, sect, ret = 0, bufsz;
+	int i, sect, ret = 0;
 	struct ppa_addr *ppas;
 
 	nvm_cpu_to_sysblk(&nvmsb, info);
 
-	/* buffer for flash page */
-	bufsz = dev->sec_size * dev->sec_per_pg * dev->nr_planes;
-	buf = kzalloc(bufsz, GFP_KERNEL);
+	buf = kzalloc(dev->pfpg_size, GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
 	memcpy(buf, &nvmsb, sizeof(struct nvm_system_block));
@@ -309,7 +306,7 @@ static int nvm_write_and_verify(struct nvm_dev *dev, struct nvm_sb_info *info,
 		}
 
 		ret = nvm_submit_ppa(dev, ppas, dev->sec_per_pg, NVM_OP_PWRITE,
-						NVM_IO_SLC_MODE, buf, bufsz);
+					NVM_IO_SLC_MODE, buf, dev->pfpg_size);
 		if (ret) {
 			pr_err("nvm: sysblk failed program (%u %u %u)\n",
 							ppas[0].g.ch,
@@ -319,7 +316,7 @@ static int nvm_write_and_verify(struct nvm_dev *dev, struct nvm_sb_info *info,
 		}
 
 		ret = nvm_submit_ppa(dev, ppas, dev->sec_per_pg, NVM_OP_PREAD,
-						NVM_IO_SLC_MODE, buf, bufsz);
+					NVM_IO_SLC_MODE, buf, dev->pfpg_size);
 		if (ret) {
 			pr_err("nvm: sysblk failed read (%u %u %u)\n",
 							ppas[0].g.ch,
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index 38814e2..f7c607f 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -323,6 +323,8 @@ struct nvm_dev {
 	int sec_per_pg; /* only sectors for a single page */
 	int pgs_per_blk;
 	int blks_per_lun;
+	int fpg_size;
+	int pfpg_size; /* size of buffer if all pages are to be read */
 	int sec_size;
 	int oob_size;
 	int mccap;
-- 
2.1.4

  parent reply	other threads:[~2016-05-06 18:03 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 ` Matias Bjørling [this message]
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 ` [PATCH 13/28] lightnvm: remove struct factory_blks Matias Bjørling
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-5-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.