Re: [PATCH 5/6] lightnvm: expose device geometry through sysfs
On 06/30/2016 10:01 PM, J Freyensee wrote: On Wed, 2016-06-29 at 16:51 +0200, Matias Bjørling wrote: From: "Simon A. F. Lund"For a host to access an Open-Channel SSD, it has to know its geometry, so that it writes and reads at the appropriate device bounds. Currently, the geometry information is kept within the kernel, and not exported to user-space for consumption. This patch exposes the configuration through sysfs and enables user-space libraries, such as liblightnvm, to use the sysfs implementation to get the geometry of an Open-Channel SSD. The sysfs entries are stored within the device hierarchy, and can be found using the "lightnvm" device type. An example configuration looks like this: /sys/class/nvme/ └── nvme0n1 ├── capabilities: 3 ├── device_mode: 1 ├── channel_parallelism: 0 ├── erase_max: 100 ├── erase_typ: 100 ├── flash_media_type: 0 ├── media_capabilities: 0x0001 ├── media_type: 0 ├── multiplane: 0x00010101 ├── num_blocks: 1022 ├── num_channels: 1 ├── num_luns: 4 ├── num_pages: 64 ├── num_planes: 1 ├── page_size: 4096 ├── prog_max: 10 ├── prog_typ: 10 ├── read_max: 1 ├── read_typ: 1 ├── sector_oob_size: 0 ├── sector_size: 4096 ├── media_manager: gennvm ├── ppa_format: 0x380830082808001010102008 ├── vendor_opcode: 0 └── version: 1 That is an awful lot of new things to add under nvme0n1-type sysfs entries when there is already a decent amount of stuff under it. You are right. These are rightfully placed under /lightnvm in the sysfs path. The description is wrong, will update it. Thanks Jay. Any chance these new things could be stuck under a separate sysfs directory under each nvmeXnY device? If these things are mainly beneficial to LightNVM, it will be easier for a LightNVM newbie to find, recognize, and consider all the important things in an Open Channel SSD solution if it's under a separate directory. And for current SSD solutions that don't seem to need these things exposed in sysfs for operation, it will make what is directly under nvmeXnY directories less cluttered. Thanks, Jay
Re: [PATCH 5/6] lightnvm: expose device geometry through sysfs
On 06/30/2016 10:01 PM, J Freyensee wrote: On Wed, 2016-06-29 at 16:51 +0200, Matias Bjørling wrote: From: "Simon A. F. Lund" For a host to access an Open-Channel SSD, it has to know its geometry, so that it writes and reads at the appropriate device bounds. Currently, the geometry information is kept within the kernel, and not exported to user-space for consumption. This patch exposes the configuration through sysfs and enables user-space libraries, such as liblightnvm, to use the sysfs implementation to get the geometry of an Open-Channel SSD. The sysfs entries are stored within the device hierarchy, and can be found using the "lightnvm" device type. An example configuration looks like this: /sys/class/nvme/ └── nvme0n1 ├── capabilities: 3 ├── device_mode: 1 ├── channel_parallelism: 0 ├── erase_max: 100 ├── erase_typ: 100 ├── flash_media_type: 0 ├── media_capabilities: 0x0001 ├── media_type: 0 ├── multiplane: 0x00010101 ├── num_blocks: 1022 ├── num_channels: 1 ├── num_luns: 4 ├── num_pages: 64 ├── num_planes: 1 ├── page_size: 4096 ├── prog_max: 10 ├── prog_typ: 10 ├── read_max: 1 ├── read_typ: 1 ├── sector_oob_size: 0 ├── sector_size: 4096 ├── media_manager: gennvm ├── ppa_format: 0x380830082808001010102008 ├── vendor_opcode: 0 └── version: 1 That is an awful lot of new things to add under nvme0n1-type sysfs entries when there is already a decent amount of stuff under it. You are right. These are rightfully placed under /lightnvm in the sysfs path. The description is wrong, will update it. Thanks Jay. Any chance these new things could be stuck under a separate sysfs directory under each nvmeXnY device? If these things are mainly beneficial to LightNVM, it will be easier for a LightNVM newbie to find, recognize, and consider all the important things in an Open Channel SSD solution if it's under a separate directory. And for current SSD solutions that don't seem to need these things exposed in sysfs for operation, it will make what is directly under nvmeXnY directories less cluttered. Thanks, Jay
Re: [PATCH 5/6] lightnvm: expose device geometry through sysfs
On Wed, 2016-06-29 at 16:51 +0200, Matias Bjørling wrote: > From: "Simon A. F. Lund"> > For a host to access an Open-Channel SSD, it has to know its > geometry, > so that it writes and reads at the appropriate device bounds. > > Currently, the geometry information is kept within the kernel, and > not > exported to user-space for consumption. This patch exposes the > configuration through sysfs and enables user-space libraries, such as > liblightnvm, to use the sysfs implementation to get the geometry of > an > Open-Channel SSD. > > The sysfs entries are stored within the device hierarchy, and can be > found using the "lightnvm" device type. > > An example configuration looks like this: > > /sys/class/nvme/ > └── nvme0n1 >├── capabilities: 3 >├── device_mode: 1 >├── channel_parallelism: 0 >├── erase_max: 100 >├── erase_typ: 100 >├── flash_media_type: 0 >├── media_capabilities: 0x0001 >├── media_type: 0 >├── multiplane: 0x00010101 >├── num_blocks: 1022 >├── num_channels: 1 >├── num_luns: 4 >├── num_pages: 64 >├── num_planes: 1 >├── page_size: 4096 >├── prog_max: 10 >├── prog_typ: 10 >├── read_max: 1 >├── read_typ: 1 >├── sector_oob_size: 0 >├── sector_size: 4096 >├── media_manager: gennvm >├── ppa_format: 0x380830082808001010102008 >├── vendor_opcode: 0 >└── version: 1 > That is an awful lot of new things to add under nvme0n1-type sysfs entries when there is already a decent amount of stuff under it. Any chance these new things could be stuck under a separate sysfs directory under each nvmeXnY device? If these things are mainly beneficial to LightNVM, it will be easier for a LightNVM newbie to find, recognize, and consider all the important things in an Open Channel SSD solution if it's under a separate directory. And for current SSD solutions that don't seem to need these things exposed in sysfs for operation, it will make what is directly under nvmeXnY directories less cluttered. Thanks, Jay
Re: [PATCH 5/6] lightnvm: expose device geometry through sysfs
On Wed, 2016-06-29 at 16:51 +0200, Matias Bjørling wrote: > From: "Simon A. F. Lund" > > For a host to access an Open-Channel SSD, it has to know its > geometry, > so that it writes and reads at the appropriate device bounds. > > Currently, the geometry information is kept within the kernel, and > not > exported to user-space for consumption. This patch exposes the > configuration through sysfs and enables user-space libraries, such as > liblightnvm, to use the sysfs implementation to get the geometry of > an > Open-Channel SSD. > > The sysfs entries are stored within the device hierarchy, and can be > found using the "lightnvm" device type. > > An example configuration looks like this: > > /sys/class/nvme/ > └── nvme0n1 >├── capabilities: 3 >├── device_mode: 1 >├── channel_parallelism: 0 >├── erase_max: 100 >├── erase_typ: 100 >├── flash_media_type: 0 >├── media_capabilities: 0x0001 >├── media_type: 0 >├── multiplane: 0x00010101 >├── num_blocks: 1022 >├── num_channels: 1 >├── num_luns: 4 >├── num_pages: 64 >├── num_planes: 1 >├── page_size: 4096 >├── prog_max: 10 >├── prog_typ: 10 >├── read_max: 1 >├── read_typ: 1 >├── sector_oob_size: 0 >├── sector_size: 4096 >├── media_manager: gennvm >├── ppa_format: 0x380830082808001010102008 >├── vendor_opcode: 0 >└── version: 1 > That is an awful lot of new things to add under nvme0n1-type sysfs entries when there is already a decent amount of stuff under it. Any chance these new things could be stuck under a separate sysfs directory under each nvmeXnY device? If these things are mainly beneficial to LightNVM, it will be easier for a LightNVM newbie to find, recognize, and consider all the important things in an Open Channel SSD solution if it's under a separate directory. And for current SSD solutions that don't seem to need these things exposed in sysfs for operation, it will make what is directly under nvmeXnY directories less cluttered. Thanks, Jay
[PATCH 5/6] lightnvm: expose device geometry through sysfs
From: "Simon A. F. Lund"For a host to access an Open-Channel SSD, it has to know its geometry, so that it writes and reads at the appropriate device bounds. Currently, the geometry information is kept within the kernel, and not exported to user-space for consumption. This patch exposes the configuration through sysfs and enables user-space libraries, such as liblightnvm, to use the sysfs implementation to get the geometry of an Open-Channel SSD. The sysfs entries are stored within the device hierarchy, and can be found using the "lightnvm" device type. An example configuration looks like this: /sys/class/nvme/ └── nvme0n1 ├── capabilities: 3 ├── device_mode: 1 ├── channel_parallelism: 0 ├── erase_max: 100 ├── erase_typ: 100 ├── flash_media_type: 0 ├── media_capabilities: 0x0001 ├── media_type: 0 ├── multiplane: 0x00010101 ├── num_blocks: 1022 ├── num_channels: 1 ├── num_luns: 4 ├── num_pages: 64 ├── num_planes: 1 ├── page_size: 4096 ├── prog_max: 10 ├── prog_typ: 10 ├── read_max: 1 ├── read_typ: 1 ├── sector_oob_size: 0 ├── sector_size: 4096 ├── media_manager: gennvm ├── ppa_format: 0x380830082808001010102008 ├── vendor_opcode: 0 └── version: 1 Signed-off-by: Simon A. F. Lund Signed-off-by: Matias Bjørling --- drivers/lightnvm/Makefile| 2 +- drivers/lightnvm/core.c | 20 +++-- drivers/lightnvm/lightnvm.h | 35 drivers/lightnvm/sysfs.c | 195 +++ drivers/nvme/host/core.c | 13 +-- drivers/nvme/host/lightnvm.c | 6 +- drivers/nvme/host/nvme.h | 20 - include/linux/lightnvm.h | 3 + 8 files changed, 277 insertions(+), 17 deletions(-) create mode 100644 drivers/lightnvm/lightnvm.h create mode 100644 drivers/lightnvm/sysfs.c diff --git a/drivers/lightnvm/Makefile b/drivers/lightnvm/Makefile index a7a0a22..1f6b652 100644 --- a/drivers/lightnvm/Makefile +++ b/drivers/lightnvm/Makefile @@ -2,6 +2,6 @@ # Makefile for Open-Channel SSDs. # -obj-$(CONFIG_NVM) := core.o sysblk.o +obj-$(CONFIG_NVM) := core.o sysblk.o sysfs.o obj-$(CONFIG_NVM_GENNVM) += gennvm.o obj-$(CONFIG_NVM_RRPC) += rrpc.o diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 0654c06..0208635 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -27,6 +27,8 @@ #include #include +#include "lightnvm.h" + static LIST_HEAD(nvm_tgt_types); static DECLARE_RWSEM(nvm_tgtt_lock); static LIST_HEAD(nvm_mgrs); @@ -598,15 +600,19 @@ static void nvm_free_mgr(struct nvm_dev *dev) dev->mt = NULL; } -static void nvm_free(struct nvm_dev *dev) +void nvm_free(struct nvm_dev *dev) { if (!dev) return; nvm_free_mgr(dev); + if (dev->dma_pool) + dev->ops->destroy_dma_pool(dev->dma_pool); + kfree(dev->lptbl); kfree(dev->lun_map); + kfree(dev); } static int nvm_init(struct nvm_dev *dev) @@ -653,11 +659,7 @@ err: static void nvm_exit(struct nvm_dev *dev) { - if (dev->dma_pool) - dev->ops->destroy_dma_pool(dev->dma_pool); - nvm_free(dev); - - pr_info("nvm: successfully unloaded\n"); + nvm_sysfs_unregister_dev(dev); } struct nvm_dev *nvm_alloc_dev(int node) @@ -688,6 +690,10 @@ int nvm_register(struct nvm_dev *dev) } } + ret = nvm_sysfs_register_dev(dev); + if (ret) + goto err_ppalist; + if (dev->identity.cap & NVM_ID_DCAP_BBLKMGMT) { ret = nvm_get_sysblock(dev, >sb); if (!ret) @@ -704,6 +710,8 @@ int nvm_register(struct nvm_dev *dev) up_write(_lock); return 0; +err_ppalist: + dev->ops->destroy_dma_pool(dev->dma_pool); err_init: kfree(dev->lun_map); return ret; diff --git a/drivers/lightnvm/lightnvm.h b/drivers/lightnvm/lightnvm.h new file mode 100644 index 000..93f1aac --- /dev/null +++ b/drivers/lightnvm/lightnvm.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 CNEX Labs. All rights reserved. + * Initial release: Matias Bjorling + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version + * 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, + * USA. + * + */ + +#ifndef LIGHTNVM_H +#define LIGHTNVM_H +
[PATCH 5/6] lightnvm: expose device geometry through sysfs
From: "Simon A. F. Lund" For a host to access an Open-Channel SSD, it has to know its geometry, so that it writes and reads at the appropriate device bounds. Currently, the geometry information is kept within the kernel, and not exported to user-space for consumption. This patch exposes the configuration through sysfs and enables user-space libraries, such as liblightnvm, to use the sysfs implementation to get the geometry of an Open-Channel SSD. The sysfs entries are stored within the device hierarchy, and can be found using the "lightnvm" device type. An example configuration looks like this: /sys/class/nvme/ └── nvme0n1 ├── capabilities: 3 ├── device_mode: 1 ├── channel_parallelism: 0 ├── erase_max: 100 ├── erase_typ: 100 ├── flash_media_type: 0 ├── media_capabilities: 0x0001 ├── media_type: 0 ├── multiplane: 0x00010101 ├── num_blocks: 1022 ├── num_channels: 1 ├── num_luns: 4 ├── num_pages: 64 ├── num_planes: 1 ├── page_size: 4096 ├── prog_max: 10 ├── prog_typ: 10 ├── read_max: 1 ├── read_typ: 1 ├── sector_oob_size: 0 ├── sector_size: 4096 ├── media_manager: gennvm ├── ppa_format: 0x380830082808001010102008 ├── vendor_opcode: 0 └── version: 1 Signed-off-by: Simon A. F. Lund Signed-off-by: Matias Bjørling --- drivers/lightnvm/Makefile| 2 +- drivers/lightnvm/core.c | 20 +++-- drivers/lightnvm/lightnvm.h | 35 drivers/lightnvm/sysfs.c | 195 +++ drivers/nvme/host/core.c | 13 +-- drivers/nvme/host/lightnvm.c | 6 +- drivers/nvme/host/nvme.h | 20 - include/linux/lightnvm.h | 3 + 8 files changed, 277 insertions(+), 17 deletions(-) create mode 100644 drivers/lightnvm/lightnvm.h create mode 100644 drivers/lightnvm/sysfs.c diff --git a/drivers/lightnvm/Makefile b/drivers/lightnvm/Makefile index a7a0a22..1f6b652 100644 --- a/drivers/lightnvm/Makefile +++ b/drivers/lightnvm/Makefile @@ -2,6 +2,6 @@ # Makefile for Open-Channel SSDs. # -obj-$(CONFIG_NVM) := core.o sysblk.o +obj-$(CONFIG_NVM) := core.o sysblk.o sysfs.o obj-$(CONFIG_NVM_GENNVM) += gennvm.o obj-$(CONFIG_NVM_RRPC) += rrpc.o diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 0654c06..0208635 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -27,6 +27,8 @@ #include #include +#include "lightnvm.h" + static LIST_HEAD(nvm_tgt_types); static DECLARE_RWSEM(nvm_tgtt_lock); static LIST_HEAD(nvm_mgrs); @@ -598,15 +600,19 @@ static void nvm_free_mgr(struct nvm_dev *dev) dev->mt = NULL; } -static void nvm_free(struct nvm_dev *dev) +void nvm_free(struct nvm_dev *dev) { if (!dev) return; nvm_free_mgr(dev); + if (dev->dma_pool) + dev->ops->destroy_dma_pool(dev->dma_pool); + kfree(dev->lptbl); kfree(dev->lun_map); + kfree(dev); } static int nvm_init(struct nvm_dev *dev) @@ -653,11 +659,7 @@ err: static void nvm_exit(struct nvm_dev *dev) { - if (dev->dma_pool) - dev->ops->destroy_dma_pool(dev->dma_pool); - nvm_free(dev); - - pr_info("nvm: successfully unloaded\n"); + nvm_sysfs_unregister_dev(dev); } struct nvm_dev *nvm_alloc_dev(int node) @@ -688,6 +690,10 @@ int nvm_register(struct nvm_dev *dev) } } + ret = nvm_sysfs_register_dev(dev); + if (ret) + goto err_ppalist; + if (dev->identity.cap & NVM_ID_DCAP_BBLKMGMT) { ret = nvm_get_sysblock(dev, >sb); if (!ret) @@ -704,6 +710,8 @@ int nvm_register(struct nvm_dev *dev) up_write(_lock); return 0; +err_ppalist: + dev->ops->destroy_dma_pool(dev->dma_pool); err_init: kfree(dev->lun_map); return ret; diff --git a/drivers/lightnvm/lightnvm.h b/drivers/lightnvm/lightnvm.h new file mode 100644 index 000..93f1aac --- /dev/null +++ b/drivers/lightnvm/lightnvm.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 CNEX Labs. All rights reserved. + * Initial release: Matias Bjorling + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version + * 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, + * USA. + * + */ + +#ifndef LIGHTNVM_H +#define LIGHTNVM_H + +#include + +/* core -> sysfs.c */ +int nvm_sysfs_register_dev(struct nvm_dev *);
[PATCH 5/6] lightnvm: expose device geometry through sysfs
From: "Simon A. F. Lund"For a host to access an Open-Channel SSD, it has to know its geometry, so that it writes and reads at the appropriate device bounds. Currently, the geometry information is kept within the kernel, and not exported to user-space for consumption. This patch exposes the configuration through sysfs and enables user-space libraries, such as liblightnvm, to use the sysfs implementation to get the geometry of an Open-Channel SSD. The sysfs entries are stored within the device hierarchy, and can be found using the "lightnvm" device type. An example configuration looks like this: /sys/class/nvme/ └── nvme0n1 ├── capabilities: 3 ├── device_mode: 1 ├── channel_parallelism: 0 ├── erase_max: 100 ├── erase_typ: 100 ├── flash_media_type: 0 ├── media_capabilities: 0x0001 ├── media_type: 0 ├── multiplane: 0x00010101 ├── num_blocks: 1022 ├── num_channels: 1 ├── num_luns: 4 ├── num_pages: 64 ├── num_planes: 1 ├── page_size: 4096 ├── prog_max: 10 ├── prog_typ: 10 ├── read_max: 1 ├── read_typ: 1 ├── sector_oob_size: 0 ├── sector_size: 4096 ├── media_manager: gennvm ├── ppa_format: 0x380830082808001010102008 ├── vendor_opcode: 0 └── version: 1 Signed-off-by: Simon A. F. Lund Signed-off-by: Matias Bjørling --- drivers/lightnvm/Makefile| 2 +- drivers/lightnvm/core.c | 20 +++-- drivers/lightnvm/lightnvm.h | 35 drivers/lightnvm/sysfs.c | 195 +++ drivers/nvme/host/core.c | 13 +-- drivers/nvme/host/lightnvm.c | 12 ++- drivers/nvme/host/nvme.h | 20 - include/linux/lightnvm.h | 3 + 8 files changed, 282 insertions(+), 18 deletions(-) create mode 100644 drivers/lightnvm/lightnvm.h create mode 100644 drivers/lightnvm/sysfs.c diff --git a/drivers/lightnvm/Makefile b/drivers/lightnvm/Makefile index a7a0a22..1f6b652 100644 --- a/drivers/lightnvm/Makefile +++ b/drivers/lightnvm/Makefile @@ -2,6 +2,6 @@ # Makefile for Open-Channel SSDs. # -obj-$(CONFIG_NVM) := core.o sysblk.o +obj-$(CONFIG_NVM) := core.o sysblk.o sysfs.o obj-$(CONFIG_NVM_GENNVM) += gennvm.o obj-$(CONFIG_NVM_RRPC) += rrpc.o diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index ad27768..661c1be 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -27,6 +27,8 @@ #include #include +#include "lightnvm.h" + static LIST_HEAD(nvm_tgt_types); static DECLARE_RWSEM(nvm_tgtt_lock); static LIST_HEAD(nvm_mgrs); @@ -593,15 +595,19 @@ static void nvm_free_mgr(struct nvm_dev *dev) dev->mt = NULL; } -static void nvm_free(struct nvm_dev *dev) +void nvm_free(struct nvm_dev *dev) { if (!dev) return; nvm_free_mgr(dev); + if (dev->dma_pool) + dev->ops->destroy_dma_pool(dev->dma_pool); + kfree(dev->lptbl); kfree(dev->lun_map); + kfree(dev); } static int nvm_init(struct nvm_dev *dev) @@ -648,11 +654,7 @@ err: static void nvm_exit(struct nvm_dev *dev) { - if (dev->dma_pool) - dev->ops->destroy_dma_pool(dev->dma_pool); - nvm_free(dev); - - pr_info("nvm: successfully unloaded\n"); + nvm_sysfs_unregister_dev(dev); } struct nvm_dev *nvm_alloc_dev(int node) @@ -683,6 +685,10 @@ int nvm_register(struct nvm_dev *dev) } } + ret = nvm_sysfs_register_dev(dev); + if (ret) + goto err_ppalist; + if (dev->identity.cap & NVM_ID_DCAP_BBLKMGMT) { ret = nvm_get_sysblock(dev, >sb); if (!ret) @@ -699,6 +705,8 @@ int nvm_register(struct nvm_dev *dev) up_write(_lock); return 0; +err_ppalist: + dev->ops->destroy_dma_pool(dev->dma_pool); err_init: kfree(dev->lun_map); return ret; diff --git a/drivers/lightnvm/lightnvm.h b/drivers/lightnvm/lightnvm.h new file mode 100644 index 000..93f1aac --- /dev/null +++ b/drivers/lightnvm/lightnvm.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 CNEX Labs. All rights reserved. + * Initial release: Matias Bjorling + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version + * 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, + * USA. + * + */ + +#ifndef LIGHTNVM_H +#define LIGHTNVM_H +
[PATCH 5/6] lightnvm: expose device geometry through sysfs
From: "Simon A. F. Lund" For a host to access an Open-Channel SSD, it has to know its geometry, so that it writes and reads at the appropriate device bounds. Currently, the geometry information is kept within the kernel, and not exported to user-space for consumption. This patch exposes the configuration through sysfs and enables user-space libraries, such as liblightnvm, to use the sysfs implementation to get the geometry of an Open-Channel SSD. The sysfs entries are stored within the device hierarchy, and can be found using the "lightnvm" device type. An example configuration looks like this: /sys/class/nvme/ └── nvme0n1 ├── capabilities: 3 ├── device_mode: 1 ├── channel_parallelism: 0 ├── erase_max: 100 ├── erase_typ: 100 ├── flash_media_type: 0 ├── media_capabilities: 0x0001 ├── media_type: 0 ├── multiplane: 0x00010101 ├── num_blocks: 1022 ├── num_channels: 1 ├── num_luns: 4 ├── num_pages: 64 ├── num_planes: 1 ├── page_size: 4096 ├── prog_max: 10 ├── prog_typ: 10 ├── read_max: 1 ├── read_typ: 1 ├── sector_oob_size: 0 ├── sector_size: 4096 ├── media_manager: gennvm ├── ppa_format: 0x380830082808001010102008 ├── vendor_opcode: 0 └── version: 1 Signed-off-by: Simon A. F. Lund Signed-off-by: Matias Bjørling --- drivers/lightnvm/Makefile| 2 +- drivers/lightnvm/core.c | 20 +++-- drivers/lightnvm/lightnvm.h | 35 drivers/lightnvm/sysfs.c | 195 +++ drivers/nvme/host/core.c | 13 +-- drivers/nvme/host/lightnvm.c | 12 ++- drivers/nvme/host/nvme.h | 20 - include/linux/lightnvm.h | 3 + 8 files changed, 282 insertions(+), 18 deletions(-) create mode 100644 drivers/lightnvm/lightnvm.h create mode 100644 drivers/lightnvm/sysfs.c diff --git a/drivers/lightnvm/Makefile b/drivers/lightnvm/Makefile index a7a0a22..1f6b652 100644 --- a/drivers/lightnvm/Makefile +++ b/drivers/lightnvm/Makefile @@ -2,6 +2,6 @@ # Makefile for Open-Channel SSDs. # -obj-$(CONFIG_NVM) := core.o sysblk.o +obj-$(CONFIG_NVM) := core.o sysblk.o sysfs.o obj-$(CONFIG_NVM_GENNVM) += gennvm.o obj-$(CONFIG_NVM_RRPC) += rrpc.o diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index ad27768..661c1be 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -27,6 +27,8 @@ #include #include +#include "lightnvm.h" + static LIST_HEAD(nvm_tgt_types); static DECLARE_RWSEM(nvm_tgtt_lock); static LIST_HEAD(nvm_mgrs); @@ -593,15 +595,19 @@ static void nvm_free_mgr(struct nvm_dev *dev) dev->mt = NULL; } -static void nvm_free(struct nvm_dev *dev) +void nvm_free(struct nvm_dev *dev) { if (!dev) return; nvm_free_mgr(dev); + if (dev->dma_pool) + dev->ops->destroy_dma_pool(dev->dma_pool); + kfree(dev->lptbl); kfree(dev->lun_map); + kfree(dev); } static int nvm_init(struct nvm_dev *dev) @@ -648,11 +654,7 @@ err: static void nvm_exit(struct nvm_dev *dev) { - if (dev->dma_pool) - dev->ops->destroy_dma_pool(dev->dma_pool); - nvm_free(dev); - - pr_info("nvm: successfully unloaded\n"); + nvm_sysfs_unregister_dev(dev); } struct nvm_dev *nvm_alloc_dev(int node) @@ -683,6 +685,10 @@ int nvm_register(struct nvm_dev *dev) } } + ret = nvm_sysfs_register_dev(dev); + if (ret) + goto err_ppalist; + if (dev->identity.cap & NVM_ID_DCAP_BBLKMGMT) { ret = nvm_get_sysblock(dev, >sb); if (!ret) @@ -699,6 +705,8 @@ int nvm_register(struct nvm_dev *dev) up_write(_lock); return 0; +err_ppalist: + dev->ops->destroy_dma_pool(dev->dma_pool); err_init: kfree(dev->lun_map); return ret; diff --git a/drivers/lightnvm/lightnvm.h b/drivers/lightnvm/lightnvm.h new file mode 100644 index 000..93f1aac --- /dev/null +++ b/drivers/lightnvm/lightnvm.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 CNEX Labs. All rights reserved. + * Initial release: Matias Bjorling + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version + * 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, + * USA. + * + */ + +#ifndef LIGHTNVM_H +#define LIGHTNVM_H + +#include + +/* core -> sysfs.c */ +int nvm_sysfs_register_dev(struct nvm_dev *);
[RFC PATCH 5/6] lightnvm: expose device geometry through sysfs
From: Simon LundFor a host to access an Open-Channel SSD, it has to know its geometry, so that it writes and reads at the appropriate device bounds. The geometry information is kept within the kernel, and not exported to user-space for consumption. This patch exposes the configuration through sysfs and enables user-space libraries, such as liblightnvm, to use the sysfs implementation to get the geometry of an Open-Channel SSD. The sysfs entries are stored within the device hierarchy, and can be found using the "lightnvm" device type. An example configuration looks like this: /sys/class/nvme/ └── nvme0n1 ├── capabilities: 3 ├── device_mode: 1 ├── channel_parallelism: 0 ├── erase_max: 100 ├── erase_typ: 100 ├── flash_media_type: 0 ├── media_capabilities: 0x0001 ├── media_type: 0 ├── multiplane: 0x00010101 ├── num_blocks: 1022 ├── num_channels: 1 ├── num_luns: 4 ├── num_pages: 64 ├── num_planes: 1 ├── page_size: 4096 ├── prog_max: 10 ├── prog_typ: 10 ├── read_max: 1 ├── read_typ: 1 ├── sector_oob_size: 0 ├── sector_size: 4096 ├── media_manager: gennvm ├── num_groups: 1 ├── ppa_format: 0x380830082808001010102008 ├── vendor_opcode: 0 └── version: 1 Signed-off-by: Simon Lund Signed-off-by: Matias Bjørling --- drivers/lightnvm/Makefile| 2 +- drivers/lightnvm/core.c | 20 +++-- drivers/lightnvm/lightnvm.h | 35 drivers/lightnvm/sysfs.c | 200 +++ drivers/nvme/host/core.c | 13 +-- drivers/nvme/host/lightnvm.c | 12 ++- drivers/nvme/host/nvme.h | 6 +- include/linux/lightnvm.h | 3 + 8 files changed, 274 insertions(+), 17 deletions(-) create mode 100644 drivers/lightnvm/lightnvm.h create mode 100644 drivers/lightnvm/sysfs.c diff --git a/drivers/lightnvm/Makefile b/drivers/lightnvm/Makefile index a7a0a22..1f6b652 100644 --- a/drivers/lightnvm/Makefile +++ b/drivers/lightnvm/Makefile @@ -2,6 +2,6 @@ # Makefile for Open-Channel SSDs. # -obj-$(CONFIG_NVM) := core.o sysblk.o +obj-$(CONFIG_NVM) := core.o sysblk.o sysfs.o obj-$(CONFIG_NVM_GENNVM) += gennvm.o obj-$(CONFIG_NVM_RRPC) += rrpc.o diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 5736c59..f71fbb9 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -27,6 +27,8 @@ #include #include +#include "lightnvm.h" + static LIST_HEAD(nvm_tgt_types); static DECLARE_RWSEM(nvm_tgtt_lock); static LIST_HEAD(nvm_mgrs); @@ -593,15 +595,19 @@ static void nvm_free_mgr(struct nvm_dev *dev) dev->mt = NULL; } -static void nvm_free(struct nvm_dev *dev) +void nvm_free(struct nvm_dev *dev) { if (!dev) return; nvm_free_mgr(dev); + if (dev->dma_pool) + dev->ops->destroy_dma_pool(dev->dma_pool); + kfree(dev->lptbl); kfree(dev->lun_map); + kfree(dev); } static int nvm_init(struct nvm_dev *dev) @@ -648,11 +654,7 @@ err: static void nvm_exit(struct nvm_dev *dev) { - if (dev->dma_pool) - dev->ops->destroy_dma_pool(dev->dma_pool); - nvm_free(dev); - - pr_info("nvm: successfully unloaded\n"); + nvm_sysfs_unregister_dev(dev); } struct nvm_dev *nvm_alloc_dev(int node) @@ -683,6 +685,10 @@ int nvm_register(struct nvm_dev *dev) } } + ret = nvm_sysfs_register_dev(dev); + if (ret) + goto err_ppalist; + if (dev->identity.cap & NVM_ID_DCAP_BBLKMGMT) { ret = nvm_get_sysblock(dev, >sb); if (!ret) @@ -699,6 +705,8 @@ int nvm_register(struct nvm_dev *dev) up_write(_lock); return 0; +err_ppalist: + dev->ops->destroy_dma_pool(dev->dma_pool); err_init: kfree(dev->lun_map); return ret; diff --git a/drivers/lightnvm/lightnvm.h b/drivers/lightnvm/lightnvm.h new file mode 100644 index 000..93f1aac --- /dev/null +++ b/drivers/lightnvm/lightnvm.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 CNEX Labs. All rights reserved. + * Initial release: Matias Bjorling + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version + * 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, + * USA. + * + */ + +#ifndef LIGHTNVM_H +#define LIGHTNVM_H + +#include
[RFC PATCH 5/6] lightnvm: expose device geometry through sysfs
From: Simon Lund For a host to access an Open-Channel SSD, it has to know its geometry, so that it writes and reads at the appropriate device bounds. The geometry information is kept within the kernel, and not exported to user-space for consumption. This patch exposes the configuration through sysfs and enables user-space libraries, such as liblightnvm, to use the sysfs implementation to get the geometry of an Open-Channel SSD. The sysfs entries are stored within the device hierarchy, and can be found using the "lightnvm" device type. An example configuration looks like this: /sys/class/nvme/ └── nvme0n1 ├── capabilities: 3 ├── device_mode: 1 ├── channel_parallelism: 0 ├── erase_max: 100 ├── erase_typ: 100 ├── flash_media_type: 0 ├── media_capabilities: 0x0001 ├── media_type: 0 ├── multiplane: 0x00010101 ├── num_blocks: 1022 ├── num_channels: 1 ├── num_luns: 4 ├── num_pages: 64 ├── num_planes: 1 ├── page_size: 4096 ├── prog_max: 10 ├── prog_typ: 10 ├── read_max: 1 ├── read_typ: 1 ├── sector_oob_size: 0 ├── sector_size: 4096 ├── media_manager: gennvm ├── num_groups: 1 ├── ppa_format: 0x380830082808001010102008 ├── vendor_opcode: 0 └── version: 1 Signed-off-by: Simon Lund Signed-off-by: Matias Bjørling --- drivers/lightnvm/Makefile| 2 +- drivers/lightnvm/core.c | 20 +++-- drivers/lightnvm/lightnvm.h | 35 drivers/lightnvm/sysfs.c | 200 +++ drivers/nvme/host/core.c | 13 +-- drivers/nvme/host/lightnvm.c | 12 ++- drivers/nvme/host/nvme.h | 6 +- include/linux/lightnvm.h | 3 + 8 files changed, 274 insertions(+), 17 deletions(-) create mode 100644 drivers/lightnvm/lightnvm.h create mode 100644 drivers/lightnvm/sysfs.c diff --git a/drivers/lightnvm/Makefile b/drivers/lightnvm/Makefile index a7a0a22..1f6b652 100644 --- a/drivers/lightnvm/Makefile +++ b/drivers/lightnvm/Makefile @@ -2,6 +2,6 @@ # Makefile for Open-Channel SSDs. # -obj-$(CONFIG_NVM) := core.o sysblk.o +obj-$(CONFIG_NVM) := core.o sysblk.o sysfs.o obj-$(CONFIG_NVM_GENNVM) += gennvm.o obj-$(CONFIG_NVM_RRPC) += rrpc.o diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 5736c59..f71fbb9 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -27,6 +27,8 @@ #include #include +#include "lightnvm.h" + static LIST_HEAD(nvm_tgt_types); static DECLARE_RWSEM(nvm_tgtt_lock); static LIST_HEAD(nvm_mgrs); @@ -593,15 +595,19 @@ static void nvm_free_mgr(struct nvm_dev *dev) dev->mt = NULL; } -static void nvm_free(struct nvm_dev *dev) +void nvm_free(struct nvm_dev *dev) { if (!dev) return; nvm_free_mgr(dev); + if (dev->dma_pool) + dev->ops->destroy_dma_pool(dev->dma_pool); + kfree(dev->lptbl); kfree(dev->lun_map); + kfree(dev); } static int nvm_init(struct nvm_dev *dev) @@ -648,11 +654,7 @@ err: static void nvm_exit(struct nvm_dev *dev) { - if (dev->dma_pool) - dev->ops->destroy_dma_pool(dev->dma_pool); - nvm_free(dev); - - pr_info("nvm: successfully unloaded\n"); + nvm_sysfs_unregister_dev(dev); } struct nvm_dev *nvm_alloc_dev(int node) @@ -683,6 +685,10 @@ int nvm_register(struct nvm_dev *dev) } } + ret = nvm_sysfs_register_dev(dev); + if (ret) + goto err_ppalist; + if (dev->identity.cap & NVM_ID_DCAP_BBLKMGMT) { ret = nvm_get_sysblock(dev, >sb); if (!ret) @@ -699,6 +705,8 @@ int nvm_register(struct nvm_dev *dev) up_write(_lock); return 0; +err_ppalist: + dev->ops->destroy_dma_pool(dev->dma_pool); err_init: kfree(dev->lun_map); return ret; diff --git a/drivers/lightnvm/lightnvm.h b/drivers/lightnvm/lightnvm.h new file mode 100644 index 000..93f1aac --- /dev/null +++ b/drivers/lightnvm/lightnvm.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 CNEX Labs. All rights reserved. + * Initial release: Matias Bjorling + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version + * 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, + * USA. + * + */ + +#ifndef LIGHTNVM_H +#define LIGHTNVM_H + +#include + +/* core -> sysfs.c */ +int nvm_sysfs_register_dev(struct nvm_dev *); +void