mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 18:23:57 -06:00
hw/block/nvme: pull lba format initialization
Pull lba format initialization code into separate function in preparation for Format NVM support. Signed-off-by: Klaus Jensen <k.jensen@samsung.com> Reviewed-by: Minwoo Im <minwoo.im.dev@gmail.com>
This commit is contained in:
parent
397fbb5b32
commit
516990f4df
1 changed files with 41 additions and 33 deletions
|
@ -32,17 +32,55 @@
|
||||||
|
|
||||||
#define MIN_DISCARD_GRANULARITY (4 * KiB)
|
#define MIN_DISCARD_GRANULARITY (4 * KiB)
|
||||||
|
|
||||||
|
static void nvme_ns_init_format(NvmeNamespace *ns)
|
||||||
|
{
|
||||||
|
NvmeIdNs *id_ns = &ns->id_ns;
|
||||||
|
BlockDriverInfo bdi;
|
||||||
|
int npdg, nlbas, ret;
|
||||||
|
|
||||||
|
nlbas = nvme_ns_nlbas(ns);
|
||||||
|
|
||||||
|
id_ns->nsze = cpu_to_le64(nlbas);
|
||||||
|
|
||||||
|
/* no thin provisioning */
|
||||||
|
id_ns->ncap = id_ns->nsze;
|
||||||
|
id_ns->nuse = id_ns->ncap;
|
||||||
|
|
||||||
|
ns->mdata_offset = nvme_l2b(ns, nlbas);
|
||||||
|
|
||||||
|
npdg = ns->blkconf.discard_granularity / nvme_lsize(ns);
|
||||||
|
|
||||||
|
ret = bdrv_get_info(blk_bs(ns->blkconf.blk), &bdi);
|
||||||
|
if (ret >= 0 && bdi.cluster_size > ns->blkconf.discard_granularity) {
|
||||||
|
npdg = bdi.cluster_size / nvme_lsize(ns);
|
||||||
|
}
|
||||||
|
|
||||||
|
id_ns->npda = id_ns->npdg = npdg - 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int nvme_ns_init(NvmeNamespace *ns, Error **errp)
|
static int nvme_ns_init(NvmeNamespace *ns, Error **errp)
|
||||||
{
|
{
|
||||||
BlockDriverInfo bdi;
|
|
||||||
NvmeIdNs *id_ns = &ns->id_ns;
|
NvmeIdNs *id_ns = &ns->id_ns;
|
||||||
int npdg, nlbas;
|
|
||||||
uint8_t ds;
|
uint8_t ds;
|
||||||
uint16_t ms;
|
uint16_t ms;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
ns->csi = NVME_CSI_NVM;
|
||||||
|
|
||||||
ns->id_ns.dlfeat = 0x1;
|
ns->id_ns.dlfeat = 0x1;
|
||||||
|
|
||||||
|
/* support DULBE and I/O optimization fields */
|
||||||
|
id_ns->nsfeat |= (0x4 | 0x10);
|
||||||
|
|
||||||
|
if (nvme_ns_shared(ns)) {
|
||||||
|
id_ns->nmic |= NVME_NMIC_NS_SHARED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* simple copy */
|
||||||
|
id_ns->mssrl = cpu_to_le16(ns->params.mssrl);
|
||||||
|
id_ns->mcl = cpu_to_le32(ns->params.mcl);
|
||||||
|
id_ns->msrc = ns->params.msrc;
|
||||||
|
|
||||||
ds = 31 - clz32(ns->blkconf.logical_block_size);
|
ds = 31 - clz32(ns->blkconf.logical_block_size);
|
||||||
ms = ns->params.ms;
|
ms = ns->params.ms;
|
||||||
|
|
||||||
|
@ -96,37 +134,7 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp)
|
||||||
id_ns->flbas |= id_ns->nlbaf;
|
id_ns->flbas |= id_ns->nlbaf;
|
||||||
|
|
||||||
lbaf_found:
|
lbaf_found:
|
||||||
nlbas = nvme_ns_nlbas(ns);
|
nvme_ns_init_format(ns);
|
||||||
|
|
||||||
id_ns->nsze = cpu_to_le64(nlbas);
|
|
||||||
ns->mdata_offset = nvme_l2b(ns, nlbas);
|
|
||||||
|
|
||||||
ns->csi = NVME_CSI_NVM;
|
|
||||||
|
|
||||||
/* no thin provisioning */
|
|
||||||
id_ns->ncap = id_ns->nsze;
|
|
||||||
id_ns->nuse = id_ns->ncap;
|
|
||||||
|
|
||||||
/* support DULBE and I/O optimization fields */
|
|
||||||
id_ns->nsfeat |= (0x4 | 0x10);
|
|
||||||
|
|
||||||
npdg = ns->blkconf.discard_granularity / nvme_lsize(ns);
|
|
||||||
|
|
||||||
if (bdrv_get_info(blk_bs(ns->blkconf.blk), &bdi) >= 0 &&
|
|
||||||
bdi.cluster_size > ns->blkconf.discard_granularity) {
|
|
||||||
npdg = bdi.cluster_size / nvme_lsize(ns);
|
|
||||||
}
|
|
||||||
|
|
||||||
id_ns->npda = id_ns->npdg = npdg - 1;
|
|
||||||
|
|
||||||
if (nvme_ns_shared(ns)) {
|
|
||||||
id_ns->nmic |= NVME_NMIC_NS_SHARED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* simple copy */
|
|
||||||
id_ns->mssrl = cpu_to_le16(ns->params.mssrl);
|
|
||||||
id_ns->mcl = cpu_to_le32(ns->params.mcl);
|
|
||||||
id_ns->msrc = ns->params.msrc;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue