Commit 4891d120 authored by Matias Bjørling's avatar Matias Bjørling Committed by Jens Axboe

lightnvm: add fpg_size and pfpg_size to struct nvm_dev

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: default avatarMatias Bjørling <m@bjorling.me>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 1145e635
...@@ -476,6 +476,8 @@ static int nvm_core_init(struct nvm_dev *dev) ...@@ -476,6 +476,8 @@ static int nvm_core_init(struct nvm_dev *dev)
dev->pgs_per_blk = grp->num_pg; dev->pgs_per_blk = grp->num_pg;
dev->blks_per_lun = grp->num_blk; dev->blks_per_lun = grp->num_blk;
dev->nr_planes = grp->num_pln; 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->sec_size = grp->csecs;
dev->oob_size = grp->sos; dev->oob_size = grp->sos;
dev->sec_per_pg = grp->fpg_sz / grp->csecs; dev->sec_per_pg = grp->fpg_sz / grp->csecs;
......
...@@ -154,13 +154,12 @@ static int nvm_scan_block(struct nvm_dev *dev, struct ppa_addr *ppa, ...@@ -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 *sblk)
{ {
struct nvm_system_block *cur; 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 /* the full buffer for a flash page is allocated. Only the first of it
* contains the system block information * contains the system block information
*/ */
cursz = dev->sec_size * dev->sec_per_pg * dev->nr_planes; cur = kmalloc(dev->pfpg_size, GFP_KERNEL);
cur = kmalloc(cursz, GFP_KERNEL);
if (!cur) if (!cur)
return -ENOMEM; return -ENOMEM;
...@@ -169,7 +168,7 @@ static int nvm_scan_block(struct nvm_dev *dev, struct ppa_addr *ppa, ...@@ -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); ppa->g.pg = ppa_to_slc(dev, pg);
ret = nvm_submit_ppa(dev, ppa, 1, NVM_OP_PREAD, NVM_IO_SLC_MODE, ret = nvm_submit_ppa(dev, ppa, 1, NVM_OP_PREAD, NVM_IO_SLC_MODE,
cur, cursz); cur, dev->pfpg_size);
if (ret) { if (ret) {
if (ret == NVM_RSP_ERR_EMPTYPAGE) { if (ret == NVM_RSP_ERR_EMPTYPAGE) {
pr_debug("nvm: sysblk scan empty ppa (%u %u %u %u)\n", 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, ...@@ -272,14 +271,12 @@ static int nvm_write_and_verify(struct nvm_dev *dev, struct nvm_sb_info *info,
{ {
struct nvm_system_block nvmsb; struct nvm_system_block nvmsb;
void *buf; void *buf;
int i, sect, ret = 0, bufsz; int i, sect, ret = 0;
struct ppa_addr *ppas; struct ppa_addr *ppas;
nvm_cpu_to_sysblk(&nvmsb, info); nvm_cpu_to_sysblk(&nvmsb, info);
/* buffer for flash page */ buf = kzalloc(dev->pfpg_size, GFP_KERNEL);
bufsz = dev->sec_size * dev->sec_per_pg * dev->nr_planes;
buf = kzalloc(bufsz, GFP_KERNEL);
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
memcpy(buf, &nvmsb, sizeof(struct nvm_system_block)); 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, ...@@ -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, 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) { if (ret) {
pr_err("nvm: sysblk failed program (%u %u %u)\n", pr_err("nvm: sysblk failed program (%u %u %u)\n",
ppas[0].g.ch, ppas[0].g.ch,
...@@ -319,7 +316,7 @@ static int nvm_write_and_verify(struct nvm_dev *dev, struct nvm_sb_info *info, ...@@ -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, 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) { if (ret) {
pr_err("nvm: sysblk failed read (%u %u %u)\n", pr_err("nvm: sysblk failed read (%u %u %u)\n",
ppas[0].g.ch, ppas[0].g.ch,
......
...@@ -323,6 +323,8 @@ struct nvm_dev { ...@@ -323,6 +323,8 @@ struct nvm_dev {
int sec_per_pg; /* only sectors for a single page */ int sec_per_pg; /* only sectors for a single page */
int pgs_per_blk; int pgs_per_blk;
int blks_per_lun; int blks_per_lun;
int fpg_size;
int pfpg_size; /* size of buffer if all pages are to be read */
int sec_size; int sec_size;
int oob_size; int oob_size;
int mccap; int mccap;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment