Commit 85136c01 authored by Matias Bjørling's avatar Matias Bjørling Committed by Jens Axboe

lightnvm: simplify geometry enumeration

Currently the geometry of an OCSSD is enumerated using a two step
approach:

First, nvm_register is called, the OCSSD identify command is issued,
and second the geometry sos and csecs values are read either from the
OCSSD identify if it is a 1.2 drive, or from the NVMe namespace data
structure if it is a 2.0 device.

This patch recombines it into a single step, such that nvm_register can
use the csecs and sos fields independent of which version is used. This
enables one to dynamically size the lightnvm subsystem dma pool.
Reviewed-by: default avatarIgor Konopko <igor.j.konopko@intel.com>
Reviewed-by: default avatarJavier González <javier@cnexlabs.com>
Signed-off-by: default avatarMatias Bjørling <mb@lightnvm.io>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 361d889f
...@@ -1145,25 +1145,23 @@ int nvm_register(struct nvm_dev *dev) ...@@ -1145,25 +1145,23 @@ int nvm_register(struct nvm_dev *dev)
if (!dev->q || !dev->ops) if (!dev->q || !dev->ops)
return -EINVAL; return -EINVAL;
ret = nvm_init(dev);
if (ret)
return ret;
dev->dma_pool = dev->ops->create_dma_pool(dev, "ppalist"); dev->dma_pool = dev->ops->create_dma_pool(dev, "ppalist");
if (!dev->dma_pool) { if (!dev->dma_pool) {
pr_err("nvm: could not create dma pool\n"); pr_err("nvm: could not create dma pool\n");
nvm_free(dev);
return -ENOMEM; return -ENOMEM;
} }
ret = nvm_init(dev);
if (ret)
goto err_init;
/* register device with a supported media manager */ /* register device with a supported media manager */
down_write(&nvm_lock); down_write(&nvm_lock);
list_add(&dev->devices, &nvm_devices); list_add(&dev->devices, &nvm_devices);
up_write(&nvm_lock); up_write(&nvm_lock);
return 0; return 0;
err_init:
dev->ops->destroy_dma_pool(dev->dma_pool);
return ret;
} }
EXPORT_SYMBOL(nvm_register); EXPORT_SYMBOL(nvm_register);
......
...@@ -1549,8 +1549,6 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id) ...@@ -1549,8 +1549,6 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
if (ns->noiob) if (ns->noiob)
nvme_set_chunk_size(ns); nvme_set_chunk_size(ns);
nvme_update_disk_info(disk, ns, id); nvme_update_disk_info(disk, ns, id);
if (ns->ndev)
nvme_nvm_update_nvm_info(ns);
#ifdef CONFIG_NVME_MULTIPATH #ifdef CONFIG_NVME_MULTIPATH
if (ns->head->disk) { if (ns->head->disk) {
nvme_update_disk_info(ns->head->disk, ns, id); nvme_update_disk_info(ns->head->disk, ns, id);
...@@ -3156,13 +3154,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) ...@@ -3156,13 +3154,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
nvme_setup_streams_ns(ctrl, ns); nvme_setup_streams_ns(ctrl, ns);
nvme_set_disk_name(disk_name, ns, ctrl, &flags); nvme_set_disk_name(disk_name, ns, ctrl, &flags);
if ((ctrl->quirks & NVME_QUIRK_LIGHTNVM) && id->vs[0] == 0x1) {
if (nvme_nvm_register(ns, disk_name, node)) {
dev_warn(ctrl->device, "LightNVM init failure\n");
goto out_unlink_ns;
}
}
disk = alloc_disk_node(0, node); disk = alloc_disk_node(0, node);
if (!disk) if (!disk)
goto out_unlink_ns; goto out_unlink_ns;
...@@ -3176,6 +3167,13 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) ...@@ -3176,6 +3167,13 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
__nvme_revalidate_disk(disk, id); __nvme_revalidate_disk(disk, id);
if ((ctrl->quirks & NVME_QUIRK_LIGHTNVM) && id->vs[0] == 0x1) {
if (nvme_nvm_register(ns, disk_name, node)) {
dev_warn(ctrl->device, "LightNVM init failure\n");
goto out_put_disk;
}
}
down_write(&ctrl->namespaces_rwsem); down_write(&ctrl->namespaces_rwsem);
list_add_tail(&ns->list, &ctrl->namespaces); list_add_tail(&ns->list, &ctrl->namespaces);
up_write(&ctrl->namespaces_rwsem); up_write(&ctrl->namespaces_rwsem);
...@@ -3189,6 +3187,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) ...@@ -3189,6 +3187,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
kfree(id); kfree(id);
return; return;
out_put_disk:
put_disk(ns->disk);
out_unlink_ns: out_unlink_ns:
mutex_lock(&ctrl->subsys->lock); mutex_lock(&ctrl->subsys->lock);
list_del_rcu(&ns->siblings); list_del_rcu(&ns->siblings);
......
...@@ -973,22 +973,11 @@ int nvme_nvm_ioctl(struct nvme_ns *ns, unsigned int cmd, unsigned long arg) ...@@ -973,22 +973,11 @@ int nvme_nvm_ioctl(struct nvme_ns *ns, unsigned int cmd, unsigned long arg)
} }
} }
void nvme_nvm_update_nvm_info(struct nvme_ns *ns)
{
struct nvm_dev *ndev = ns->ndev;
struct nvm_geo *geo = &ndev->geo;
if (geo->version == NVM_OCSSD_SPEC_12)
return;
geo->csecs = 1 << ns->lba_shift;
geo->sos = ns->ms;
}
int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, int node) int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, int node)
{ {
struct request_queue *q = ns->queue; struct request_queue *q = ns->queue;
struct nvm_dev *dev; struct nvm_dev *dev;
struct nvm_geo *geo;
_nvme_nvm_check_size(); _nvme_nvm_check_size();
...@@ -996,6 +985,11 @@ int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, int node) ...@@ -996,6 +985,11 @@ int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, int node)
if (!dev) if (!dev)
return -ENOMEM; return -ENOMEM;
/* Note that csecs and sos will be overridden if it is a 1.2 drive. */
geo = &dev->geo;
geo->csecs = 1 << ns->lba_shift;
geo->sos = ns->ms;
dev->q = q; dev->q = q;
memcpy(dev->name, disk_name, DISK_NAME_LEN); memcpy(dev->name, disk_name, DISK_NAME_LEN);
dev->ops = &nvme_nvm_dev_ops; dev->ops = &nvme_nvm_dev_ops;
......
...@@ -540,13 +540,11 @@ static inline void nvme_mpath_stop(struct nvme_ctrl *ctrl) ...@@ -540,13 +540,11 @@ static inline void nvme_mpath_stop(struct nvme_ctrl *ctrl)
#endif /* CONFIG_NVME_MULTIPATH */ #endif /* CONFIG_NVME_MULTIPATH */
#ifdef CONFIG_NVM #ifdef CONFIG_NVM
void nvme_nvm_update_nvm_info(struct nvme_ns *ns);
int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, int node); int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, int node);
void nvme_nvm_unregister(struct nvme_ns *ns); void nvme_nvm_unregister(struct nvme_ns *ns);
extern const struct attribute_group nvme_nvm_attr_group; extern const struct attribute_group nvme_nvm_attr_group;
int nvme_nvm_ioctl(struct nvme_ns *ns, unsigned int cmd, unsigned long arg); int nvme_nvm_ioctl(struct nvme_ns *ns, unsigned int cmd, unsigned long arg);
#else #else
static inline void nvme_nvm_update_nvm_info(struct nvme_ns *ns) {};
static inline int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, static inline int nvme_nvm_register(struct nvme_ns *ns, char *disk_name,
int node) int node)
{ {
......
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