Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753091AbcD0RxY (ORCPT ); Wed, 27 Apr 2016 13:53:24 -0400 Received: from mail-bl2on0065.outbound.protection.outlook.com ([65.55.169.65]:60320 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750777AbcD0RxW (ORCPT ); Wed, 27 Apr 2016 13:53:22 -0400 Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=cnexlabs.com; From: "Simon A. F. Lund" To: , , CC: , "Simon A. F. Lund" Subject: [RFC PATCH] lightnvm: expose configuration through sysfs Date: Wed, 27 Apr 2016 10:18:57 -0700 Message-ID: <1461777537-8145-2-git-send-email-slund@cnexlabs.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1461777537-8145-1-git-send-email-slund@cnexlabs.com> References: <1461777537-8145-1-git-send-email-slund@cnexlabs.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [50.207.153.190] X-ClientProxiedBy: BLUPR14CA0041.namprd14.prod.outlook.com (10.163.77.179) To DM2PR0601MB0985.namprd06.prod.outlook.com (10.160.26.15) X-MS-Office365-Filtering-Correlation-Id: e6686c8d-555f-414b-6d53-08d36ec020a4 X-Microsoft-Exchange-Diagnostics: 1;DM2PR0601MB0985;2:biaMozdBZC69Y54qEXvB7f3qrLhzKXD+G6uDdSk1JRk+rLr/kEzBrSPflYdJZOm8CE2f6om7AWoATUPX3IPIlhgB4lYEu++JWkg8OOurb3j8z0Rsk0nWq6lZW8qzP/6M9J8Xlh91rkp/CNIU9vm3lTTW4n5mjMISkftNrmYiFDnlZtP8ItTis4L8yMWHbOAn;3:vbw5qASCuOBGQoA84HLpFXPy6e551vibEbsx55GxZRCbJS1AjnO27LGMXnueX/ArOb9ExCkOrnyCFxy4HasUPnHeyX4Q3BRBTdb+C4P8CWv1iuj9+ea9RTWRRCMHVoei;25:wZ1s3ZvkDHulYH5P0mTnPLAFskA5JyX93SXnNXZFa3M8z5dQGE2/MiBPQfL2vEwIZVf4VL3zN2Y1+BvHBRiKffY5MoQLVQSL9EXJCGhwUFYuUsHySnBf+cjdhwcCUWsCcwEpsBVzFGTreozz8WkrYTF1pDhTFPwcx9E+x2HNjaeha0TNnAV20UJxakjBpEUUTpXThWV1XUmmW51HhUO2ix2ZttJ5E+X+k/kIJtqAAK1uuAzwa8+sSuS1tkxZPLhq1O8BKFoo4gQQVM+MhoQQsZh3rIz1vEwel9ZOA9xGceMBBifVYtsNCAK8XDJc5VyzWhcssFBjKmPPEPqB4kGfog==;20:98ggguv/RVUN78xX/jbd3wu9aVnI9pAiepo7DMjjpmGvICaq8uw7w50T/yGSytvvuLpDXOGpvEQfPN50WAL1ehWZXUqM0xIUmevQRk6HdkuCdbuGIg0TuqMkGIrXUHhl2+RWD6PrFp+i9xf7Zq8ury9wbfhjAfoKEA5zBqIdLxg= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0601MB0985; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521072)(6040130)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041072)(6043046);SRVR:DM2PR0601MB0985;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0601MB0985; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0601MB0985;4:Wk59HlLdlQnscXF/+98WzcNDgb0zmIo1prVqOISnxreSDE7jvYuD5RFTNML4SFoBFxnEmxIZKWbzfrrLZNvos9+T6lLmMDXpjcEEB53ICYlHBIX7pROtg9So5f5vYrTQtwwsJd1bx9Nr55XFeACAyYSLiY9YSU1QTJvnoyQw478rQwuO8A6vQ1w0F9HojvGrWEHdDLN6Zls0/vZ8F9LoKDLPlwvbTn+lQQrwbQG5qz4kbah4gGGjlsasqvydxUsVTVTr9YHTqnPuy/lcnLWPkcbZxHGlkDZdwDPobwzt3hFJMHMfqwZzBVB1B+xDG/KH56TQ8Y6AntDZo0QyEAyRxrfYgyp3Y0SharG3LSNekdwj5I5JybKgYH3/7L48uqi5puid2SSp5lYgLkYU691GJKRzY2M1a46YOtBdn6gER3eto7SxWkPQRhnibgTNcAj2izFgT8ib0KJZMKwIFAbKyQ== X-Forefront-PRVS: 0925081676 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(50944005)(36756003)(2950100001)(586003)(1096002)(15975445007)(50986999)(77096005)(92566002)(76176999)(5001770100001)(107886002)(5004730100002)(5820100001)(50466002)(33646002)(6116002)(4326007)(189998001)(5008740100001)(2870700001)(66066001)(19580405001)(47776003)(229853001)(3846002)(19580395003)(53416004)(4001430100002)(81166005)(2201001)(23676002)(2906002)(42186005)(50226002)(575784001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR0601MB0985;H:tiger.cnexlabs.com;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTJQUjA2MDFNQjA5ODU7MjM6MzlFVUJVOVhFWWZkU0tvbWtBSFdRbzdp?= =?utf-8?B?YzlYS2VjdlBLak9idFZWSW9IdnZEWGdYT2U3LzJPNWpCWTE5Uno4RzU1S2xP?= =?utf-8?B?SVFVQVZ3bFI5YmJzODNrUGthTWFqbk9ZcVJVUnUrOEFyVTU2b3FWYWFpVHhm?= =?utf-8?B?cXJFKy92aEJseEtMWjltMFdGazhMeWlra0g3dEE2cDF4ZjltN0ExYnNIdEVN?= =?utf-8?B?SlhweUw5TnVYb0VwcERrMGMrK2VRZ215NllGQldnbFNwMTg5N1NtTFZMRmsz?= =?utf-8?B?bGVBTjRBUlBvM25tN3ovRWNpNFN3MzVYMjBkSzd0L2pmSWlscTMwWnpYenI3?= =?utf-8?B?eVYvdTZQYzVVdVZPN04vNURZeDQ3cURxVGh6UFNkYlJUUStZYzdDQmU3bW1U?= =?utf-8?B?enZmSGxuWUpYZmcvNFl0c1V2aEVTMm9hUmp3Mm53dmE0UzJ5di9EQTNSUkxO?= =?utf-8?B?OVVyZUR5VzRERUJFTTlwQUFIL0J5bGJLdEI4ZkhHOWptVDJ3Vkd5aTdTbFZ2?= =?utf-8?B?eCtUUVdkMk5VQ2gzeDNhMVgrZk00Q2Z0bmNaUWJuSTdnbkRhcUdnWjRVdEUy?= =?utf-8?B?Ulc4aDRLTkhzWEp6WjVHMXZzUVJydXBJWnlsQzBtSWtYSDljQStwZFNLTzVZ?= =?utf-8?B?VGpaSzZ1OVFqeWQ4ZG52aWM2WUxmYkpOL2c3MzVwQU5SeS9IZW9SRHdva3BN?= =?utf-8?B?VGgrRFo3bXJ5d0NvRW5xTGZyQ3JNYlJ3TGJPK3kyaGZTRFBzVnl1R1JVMHBo?= =?utf-8?B?T1FwendqTHZtQ1J1YXYwaU5iZ2hzTU9WbjU0TjJrMkZSSVJHQ3E5aVk0S1RU?= =?utf-8?B?SkZiYW9OM3VVZHFlNUkwdFR5WlE3NkIzcTNqcmNlTjFaWHVlWjBpbm12SGJ2?= =?utf-8?B?TUZKRFdDdURObUdoTUtteUQyNWdrVDVudlBrK1VMckhGcS9pZlN6RnlidUVL?= =?utf-8?B?a2x2OU05TEVsSW9FZlBQTVJCNVBmcXZoTE5jZjRGM2cwQ3A2SEJiRWZDekdZ?= =?utf-8?B?ekNKSmhhMDhPYUZCaU03YTVmR0ZIb2NrTGNUeFg5VFA3UTdJWGI4R0RCc2hn?= =?utf-8?B?bHR5S3I4U1czZktKMWdkWnRxT2lOS2srbEtFVlE0QWJYZWVLVVVILzN4T2dp?= =?utf-8?B?L0liaFhBSnZPTk5aVjIxd3R3OEFQeU15TUVWN2l0WjdLYjBwOEs4R0IzRGlw?= =?utf-8?B?cGxINExXSnR6ckFnMXFwYzdlVWdPemk5UmRjTTVuTUh0OXVWSWI2RDdLWWJS?= =?utf-8?B?US85OUZIalhJME94VXo2dm11NnhRRVJWOW5YUC9paHY1UVpXOGhXVEdiV3Bz?= =?utf-8?B?SHAzdk84ckpjVTczdXpqL0JGYkQyb1BwRXd2Sm94djFrU2QzbFBHK2owSG9o?= =?utf-8?B?U28vYmFCVUFNVDd0MFdQSmZHZkJzeWdDYXl3Tk4xZ3FhYkJkZU84WHlWVzhk?= =?utf-8?Q?H1xgCsmk=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR0601MB0985;5:yRAPyKNOnq1Ddhh6k+yV2ouxOAicnrFqETJLNuXHDW5dCTzrXNdWHv6TV6qDHG2cktBZwL3PjZVMyE/v9ZhSPuPhJfN9sOvC/RIeTsNr97F3r/z38JXrdCHt3VTRNNbpXqo7FCI4lACe84DY6NmBZw==;24:Qaic9t3Mt5jiudDVusDRGHOccZ17vm/Mhtssflzqu6htTm2H7JuJeTolsQPMNhCbY1IQJ0wbl9E2DsQ9KYuNrUrUc2smtyya46jVvncTXsU=;7:WDZqOKtncYgOYHSkI+ZWrUp+iVYU3iQIpeIpV4sqCoFco+mTovxs0Ley+8U7I/mIG9QCLuSipnLadGuJjYnZQ8edKmqATl+cqzNrdRJuQG5bC7rBYmVJQPfCvf4Aibs5Qj/esfdsy/JU8mWkBMD1YQnEaSSuHukvolbRJMItaheXfJSY9my7hNQUlGqkmSnM SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cnexlabs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2016 17:19:44.1357 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0601MB0985 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 28692 Lines: 932 An open-channel SSD exposes its geometry to the host. Allowing the host to know the boundaries of the LUNs, flash blocks, and flags pages, enabling the host to write to its physical media. The configuration 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 configuration looks like this: /sys/devices/virtual/misc/lightnvm ├── devices │   └── nvme0n1 │   ├── capabilities │   ├── device_mode │   ├── grp0 │   │   ├── channel_parallelism │   │   ├── erase_max │   │   ├── erase_typ │   │   ├── flash_media_type │   │   ├── media_capabilities │   │   ├── media_type │   │   ├── multiplane │   │   ├── num_blocks │   │   ├── num_channels │   │   ├── num_luns │   │   ├── num_pages │   │   ├── num_planes │   │   ├── page_size │   │   ├── prog_max │   │   ├── prog_typ │   │   ├── read_max │   │   ├── read_typ │   │   ├── sector_oob_size │   │   └── sector_size │   ├── media_manager │   ├── num_groups │   ├── ppa_format │   ├── vendor_opcode │   └── version └── targets └── tgt0 └── type With sample values from qemu instance: /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/capabilities: 3 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/device_mode: 1 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/channel_parallelism: 0 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/erase_max: 1000000 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/erase_typ: 1000000 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/flash_media_type: 0 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/media_capabilities: 0x00000001 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/media_type: 0 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/multiplane: 0x00010101 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/num_blocks: 1022 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/num_channels: 1 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/num_luns: 4 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/num_pages: 64 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/num_planes: 1 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/page_size: 4096 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/prog_max: 100000 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/prog_typ: 100000 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/read_max: 10000 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/read_typ: 10000 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/sector_oob_size: 0 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/grp0/sector_size: 4096 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/media_manager: gennvm /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/num_groups: 1 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/ppa_format: 0x380830082808001010102008 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/vendor_opcode: 0 /sys/devices/virtual/misc/lightnvm/devices/nvme0n1/version: 1 /sys/devices/virtual/misc/lightnvm/targets/tgt0/type: rrpc Signed-off-by: Simon A. F. Lund --- Documentation/ABI/testing/sysfs-lightnvm | 244 ++++++++++++++++++ drivers/lightnvm/Makefile | 2 +- drivers/lightnvm/core.c | 33 ++- drivers/lightnvm/sysfs.c | 418 +++++++++++++++++++++++++++++++ drivers/lightnvm/sysfs.h | 18 ++ include/linux/lightnvm.h | 4 + 6 files changed, 712 insertions(+), 7 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-lightnvm create mode 100644 drivers/lightnvm/sysfs.c create mode 100644 drivers/lightnvm/sysfs.h diff --git a/Documentation/ABI/testing/sysfs-lightnvm b/Documentation/ABI/testing/sysfs-lightnvm new file mode 100644 index 0000000..7cf9e78 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-lightnvm @@ -0,0 +1,244 @@ +What: /sys/.../lightnvm/devices//capabilities +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Device capabilities and feature support. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices//device_mode +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Current device operating mode. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices//media_manager +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Media manager type e.g. "gennvm". +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices//num_groups +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Number of configuration groups. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices//ppa_format +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Physical Page Address format + Reported as hex. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices//vendor_opcode +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Vendor NVM opcode command set. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices//version +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Version identifier. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///channel_parallelism +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Number of parallel commands in-flight within a channel. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///erase_max +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Maximum page erase time (in ns). +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///erase_typ +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Type page erase time (in ns). +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///flash_media_type +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + 0: Single bit level cell flash (SLC) + 1: Two bit level cell flash (MLC) + 2: Three bit level cell flash (TLC) +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///media_capabilities +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Media and controller capabilties for flash memories. + Represented as a bit-string, reported as hex. + + Bit Feature + =============================== + 0: SLC mode + 1: Command suspension + 2: Scramble ON/OFF + 3: Encryption +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///media_type +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + The rest of the attributes are determined by the value + of the media_type. + + 0: NAND Flash Memory +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///multiplane +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Support for multi-plane operations. + Represented as a bitstring reported as hex. + + Bit Feature + =============================== + 0: Single plane read + 1: Dual plane read + 2: Quad plane read + 8: Single plane program + 9: Dual plane program + 10: Quad plane program + 16: Single plane erase + 17: Dual plane erase + 18: Quad plane erase +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///num_blocks +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Number of flash block per plane. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///num_channels +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Number of channels in controller. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///num_luns +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Number of Logical Unit Numbers (LUNs) per channel. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///num_pages +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Number of flash pages per block. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///num_planes +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Number of flash planes per LUN. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///page_size +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Number of bytes per flash page. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///prog_max +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Maximum page program time (in ns). +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///prog_typ +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Typical page program time (in ns). +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///read_max +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Maximum page read time (in ns). +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///read_typ +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Typical page read time (in ns). +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///sector_oob_size +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Per-sector metadata (in bytes) +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/devices///sector_size +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Controller defined minimum data unit protected by ECC + (in bytes). For example 4096 bytes. +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + +What: /sys/.../lightnvm/targets//type +Date: March 2016 +KernelVersion: 4.7 +Contact: "Simon A. F. Lund" +Description: + Target type e.g. "rrpc", "pblk". +Users: lnvm - https://github.com/OpenChannelSSD/lnvm + 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 0296223..8a7f079 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -30,6 +30,8 @@ #include #include +#include "sysfs.h" + static LIST_HEAD(nvm_tgt_types); static LIST_HEAD(nvm_mgrs); static LIST_HEAD(nvm_devices); @@ -684,6 +686,10 @@ int nvm_register(struct request_queue *q, char *disk_name, } } + ret = nvm_sysfs_register_dev(dev); + if (ret) + goto err_ppalist; + if (dev->identity.cap & NVM_ID_DCAP_BBLKMGMT) { ret = nvm_get_sysblock(dev, &dev->sb); if (!ret) @@ -700,6 +706,9 @@ int nvm_register(struct request_queue *q, char *disk_name, up_write(&nvm_lock); return 0; +err_ppalist: + if (dev->ppalist_pool) + dev->ops->destroy_dma_pool(dev->ppalist_pool); err_init: kfree(dev->lun_map); kfree(dev); @@ -724,7 +733,8 @@ void nvm_unregister(char *disk_name) up_write(&nvm_lock); nvm_exit(dev); - kfree(dev); + + nvm_sysfs_unregister_dev(dev); } EXPORT_SYMBOL(nvm_unregister); @@ -763,7 +773,7 @@ static int nvm_create_target(struct nvm_dev *dev, } up_write(&nvm_lock); - t = kmalloc(sizeof(struct nvm_target), GFP_KERNEL); + t = kzalloc(sizeof(struct nvm_target), GFP_KERNEL); if (!t) return -ENOMEM; @@ -792,12 +802,15 @@ static int nvm_create_target(struct nvm_dev *dev, blk_queue_max_hw_sectors(tqueue, 8 * dev->ops->max_phys_sect); - set_capacity(tdisk, tt->capacity(targetdata)); - add_disk(tdisk); - t->type = tt; t->disk = tdisk; + if (nvm_sysfs_register_target(t)) + goto err_init; + + set_capacity(tdisk, tt->capacity(targetdata)); + add_disk(tdisk); + down_write(&nvm_lock); list_add_tail(&t->list, &nvm_targets); up_write(&nvm_lock); @@ -829,7 +842,8 @@ static void nvm_remove_target(struct nvm_target *t) put_disk(tdisk); list_del(&t->list); - kfree(t); + + nvm_sysfs_unregister_target(t); } static int __nvm_configure_create(struct nvm_ioctl_create *create) @@ -1276,11 +1290,18 @@ static int __init nvm_mod_init(void) if (ret) pr_err("nvm: misc_register failed for control device"); + ret = nvm_sysfs_register(&_nvm_misc); + if (ret) { + pr_err("nvm: sysfs registration failed.\n"); + misc_deregister(&_nvm_misc); + } + return ret; } static void __exit nvm_mod_exit(void) { + nvm_sysfs_unregister(&_nvm_misc); misc_deregister(&_nvm_misc); } diff --git a/drivers/lightnvm/sysfs.c b/drivers/lightnvm/sysfs.c new file mode 100644 index 0000000..725f8df --- /dev/null +++ b/drivers/lightnvm/sysfs.c @@ -0,0 +1,418 @@ +#include +#include +#include +#include + +#include "sysfs.h" + +static struct kset *devices; +static struct kset *targets; + +/* + * Functions and data structures for LightNVM targets in sysfs. + * This file contains the show-functions, release-functions, default_attrs, + * sysfs_register* function, and ktypes. + */ + +#define NVM_TARGET_ATTR_RO(_name) \ + static struct attribute nvm_target_##_name##_attr = { \ + .name = __stringify(_name), \ + .mode = S_IRUGO \ + } + +#define NVM_TARGET_ATTR_LIST(_name) (&nvm_target_##_name##_attr) + +NVM_TARGET_ATTR_RO(type); + +static struct attribute *nvm_target_default_attrs[] = { + NVM_TARGET_ATTR_LIST(type), + NULL, +}; + +static ssize_t nvm_target_attr_show(struct kobject *kobj, + struct attribute *attr, + char *page) +{ + struct nvm_target *target = container_of(kobj, struct nvm_target, kobj); + + if (strcmp(attr->name, "type") == 0) { + return scnprintf(page, PAGE_SIZE, "%s\n", + target->type->name); + } else { + return scnprintf(page, PAGE_SIZE, + "Unhandled attr(%s) in `nvm_target_attr_show`\n", + attr->name); + } +} + +static const struct sysfs_ops target_sysfs_ops = { + .show = nvm_target_attr_show, +}; + +static void nvm_target_release(struct kobject *kobj) +{ + struct nvm_target *tgt = container_of(kobj, struct nvm_target, kobj); + + pr_debug("nvm/sysfs: `nvm_target_release`\n"); + + kfree(tgt); +} + +static struct kobj_type nvm_target_ktype = { + .sysfs_ops = &target_sysfs_ops, + .default_attrs = nvm_target_default_attrs, + .release = nvm_target_release +}; + +void nvm_sysfs_unregister_target(struct nvm_target *target) +{ + kobject_del(&target->kobj); + kobject_put(&target->kobj); +} + +int nvm_sysfs_register_target(struct nvm_target *target) +{ + int ret; + + target->kobj.kset = targets; + ret = kobject_init_and_add(&target->kobj, &nvm_target_ktype, NULL, "%s", + target->disk->disk_name); + if (ret < 0) { + pr_err("nvm/sysfs: `_register_target` failed.\n"); + kobject_put(&target->kobj); + return ret; + } + + kobject_uevent(&target->kobj, KOBJ_ADD); + + return 0; +} + +/* + * Functions and data structures for exposing + * group-information of LightNVM enabled devices. + * + * NOTE: these are internal to sysfs.c and used by `nvm_sysfs_[un]register_dev`. + */ + +static void nvm_grp_release(struct kobject *kobj) +{ + pr_debug("nvm/sysfs: called `nvm_grp_release`.\n"); + + /* This does nothing since `nvm_id_group` information is embedded inside + * `nvm_dev`. Management of `nvm_id_group` is therefore handled by the + * release of `nvm_dev_release`. + */ +} + +#define NVM_GRP_ATTR_RO(_name) \ + static struct attribute nvm_grp_##_name##_attr = { \ + .name = __stringify(_name), \ + .mode = S_IRUGO \ + } + +#define NVM_GRP_ATTR_LIST(_name) (&nvm_grp_##_name##_attr) + +NVM_GRP_ATTR_RO(media_type); +NVM_GRP_ATTR_RO(flash_media_type); +NVM_GRP_ATTR_RO(num_channels); +NVM_GRP_ATTR_RO(num_luns); +NVM_GRP_ATTR_RO(num_planes); +NVM_GRP_ATTR_RO(num_blocks); +NVM_GRP_ATTR_RO(num_pages); +NVM_GRP_ATTR_RO(page_size); +NVM_GRP_ATTR_RO(sector_size); +NVM_GRP_ATTR_RO(sector_oob_size); +NVM_GRP_ATTR_RO(read_typ); +NVM_GRP_ATTR_RO(read_max); +NVM_GRP_ATTR_RO(prog_typ); +NVM_GRP_ATTR_RO(prog_max); +NVM_GRP_ATTR_RO(erase_typ); +NVM_GRP_ATTR_RO(erase_max); +NVM_GRP_ATTR_RO(multiplane); +NVM_GRP_ATTR_RO(media_capabilities); +NVM_GRP_ATTR_RO(channel_parallelism); + +static struct attribute *nvm_grp_default_attrs[] = { + NVM_GRP_ATTR_LIST(media_type), + NVM_GRP_ATTR_LIST(flash_media_type), + NVM_GRP_ATTR_LIST(num_channels), + NVM_GRP_ATTR_LIST(num_luns), + NVM_GRP_ATTR_LIST(num_planes), + NVM_GRP_ATTR_LIST(num_blocks), + NVM_GRP_ATTR_LIST(num_pages), + NVM_GRP_ATTR_LIST(page_size), + NVM_GRP_ATTR_LIST(sector_size), + NVM_GRP_ATTR_LIST(sector_oob_size), + NVM_GRP_ATTR_LIST(read_typ), + NVM_GRP_ATTR_LIST(read_max), + NVM_GRP_ATTR_LIST(prog_typ), + NVM_GRP_ATTR_LIST(prog_max), + NVM_GRP_ATTR_LIST(erase_typ), + NVM_GRP_ATTR_LIST(erase_max), + NVM_GRP_ATTR_LIST(multiplane), + NVM_GRP_ATTR_LIST(media_capabilities), + NVM_GRP_ATTR_LIST(channel_parallelism), + NULL, +}; + +static ssize_t nvm_grp_attr_show(struct kobject *kobj, + struct attribute *attr, + char *page) +{ + struct nvm_id_group *grp = container_of(kobj, struct nvm_id_group, + kobj); + + if (strcmp(attr->name, "media_type") == 0) { /* u8 */ + return scnprintf(page, PAGE_SIZE, "%u\n", grp->mtype); + } else if (strcmp(attr->name, "flash_media_type") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->fmtype); + } else if (strcmp(attr->name, "num_channels") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->num_ch); + } else if (strcmp(attr->name, "num_luns") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->num_lun); + } else if (strcmp(attr->name, "num_planes") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->num_pln); + } else if (strcmp(attr->name, "num_blocks") == 0) { /* u16 */ + return scnprintf(page, PAGE_SIZE, "%u\n", grp->num_blk); + } else if (strcmp(attr->name, "num_pages") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->num_pg); + } else if (strcmp(attr->name, "page_size") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->fpg_sz); + } else if (strcmp(attr->name, "sector_size") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->csecs); + } else if (strcmp(attr->name, "sector_oob_size") == 0) {/* u32 */ + return scnprintf(page, PAGE_SIZE, "%u\n", grp->sos); + } else if (strcmp(attr->name, "read_typ") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->trdt); + } else if (strcmp(attr->name, "read_max") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->trdm); + } else if (strcmp(attr->name, "prog_typ") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->tprt); + } else if (strcmp(attr->name, "prog_max") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->tprm); + } else if (strcmp(attr->name, "erase_typ") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->tbet); + } else if (strcmp(attr->name, "erase_max") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", grp->tbem); + } else if (strcmp(attr->name, "multiplane") == 0) { + return scnprintf(page, PAGE_SIZE, "0x%08x\n", grp->mpos); + } else if (strcmp(attr->name, "media_capabilities") == 0) { + return scnprintf(page, PAGE_SIZE, "0x%08x\n", grp->mccap); + } else if (strcmp(attr->name, "channel_parallelism") == 0) {/* u16 */ + return scnprintf(page, PAGE_SIZE, "%u\n", grp->cpar); + } else { + return scnprintf(page, PAGE_SIZE, + "Unhandled attr(%s) in `nvm_grp_attr_show`\n", + attr->name); + } +} + +static const struct sysfs_ops nvm_grp_sysfs_ops = { + .show = nvm_grp_attr_show, +}; + +static struct kobj_type nvm_grp_ktype = { + .sysfs_ops = &nvm_grp_sysfs_ops, + .default_attrs = nvm_grp_default_attrs, + .release = nvm_grp_release +}; + +void nvm_sysfs_unregister_grps(struct nvm_dev *dev) +{ + int i; + + for (i = 0; i < dev->identity.cgrps; i++) { + kobject_del(&dev->identity.groups[i].kobj); + kobject_put(&dev->identity.groups[i].kobj); + kobject_put(&dev->kobj); + } +} + +static int nvm_sysfs_register_grps(struct nvm_dev *dev) +{ + int i, ret; + + for (i = 0; i < dev->identity.cgrps; i++) { + ret = kobject_init_and_add(&dev->identity.groups[i].kobj, + &nvm_grp_ktype, + kobject_get(&dev->kobj), + "grp%u", i); + if (ret < 0) { + pr_err("nvm/sysfs: `_register_grps` failed(%d)\n", ret); + goto grps_error; + } + + kobject_uevent(&dev->identity.groups[i].kobj, KOBJ_ADD); + } + + return 0; + +grps_error: + kobject_put(&dev->identity.groups[i].kobj); /* The failed grp*/ + kobject_put(&dev->kobj); + + for (i = i - 1; i > 0; i--) { /* Successful grps */ + kobject_del(&dev->identity.groups[i].kobj); + kobject_put(&dev->identity.groups[i].kobj); + kobject_put(&dev->kobj); + } + + return ret; +} + +/* + * Functions and data structures for exposing LightNVM enabled devices. + */ + +#define NVM_DEV_ATTR_RO(_name) \ + static struct attribute nvm_dev_##_name##_attr = { \ + .name = __stringify(_name), \ + .mode = S_IRUGO \ + } + +#define NVM_DEV_ATTR_LIST(_name) (&nvm_dev_##_name##_attr) + +NVM_DEV_ATTR_RO(version); +NVM_DEV_ATTR_RO(vendor_opcode); +NVM_DEV_ATTR_RO(num_groups); +NVM_DEV_ATTR_RO(capabilities); +NVM_DEV_ATTR_RO(device_mode); +NVM_DEV_ATTR_RO(ppa_format); +NVM_DEV_ATTR_RO(media_manager); + +static struct attribute *nvm_dev_default_attrs[] = { + NVM_DEV_ATTR_LIST(version), + NVM_DEV_ATTR_LIST(vendor_opcode), + NVM_DEV_ATTR_LIST(num_groups), + NVM_DEV_ATTR_LIST(capabilities), + NVM_DEV_ATTR_LIST(device_mode), + NVM_DEV_ATTR_LIST(ppa_format), + NVM_DEV_ATTR_LIST(media_manager), + NULL, +}; + +static ssize_t nvm_dev_attr_show(struct kobject *kobj, struct attribute *attr, + char *page) +{ + struct nvm_dev *dev = container_of(kobj, struct nvm_dev, kobj); + struct nvm_id *id = &dev->identity; + + if (strcmp(attr->name, "version") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", id->ver_id); + } else if (strcmp(attr->name, "vendor_opcode") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", id->vmnt); + } else if (strcmp(attr->name, "num_groups") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", id->cgrps); + } else if (strcmp(attr->name, "capabilities") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", id->cap); + } else if (strcmp(attr->name, "device_mode") == 0) { + return scnprintf(page, PAGE_SIZE, "%u\n", id->dom); + } else if (strcmp(attr->name, "media_manager") == 0) { + if (!dev->mt) + return scnprintf(page, PAGE_SIZE, "%s\n", "none"); + return scnprintf(page, PAGE_SIZE, "%s\n", dev->mt->name); + } else if (strcmp(attr->name, "ppa_format") == 0) { + return scnprintf(page, PAGE_SIZE, + "0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", + id->ppaf.ch_offset, id->ppaf.ch_len, + id->ppaf.lun_offset, id->ppaf.lun_len, + id->ppaf.pln_offset, id->ppaf.pln_len, + id->ppaf.blk_offset, id->ppaf.blk_len, + id->ppaf.pg_offset, id->ppaf.pg_len, + id->ppaf.sect_offset, id->ppaf.sect_len); + } else { + return scnprintf(page, + PAGE_SIZE, + "Unhandled attr(%s) in `nvm_dev_attr_show`\n", + attr->name); + } +} + +static const struct sysfs_ops nvm_dev_sysfs_ops = { + .show = nvm_dev_attr_show, +}; + +static void nvm_dev_release(struct kobject *kobj) +{ + struct nvm_dev *dev = container_of(kobj, struct nvm_dev, kobj); + + pr_debug("nvm/sysfs: `nvm_dev_release`\n"); + + kfree(dev); +} + +static struct kobj_type nvm_dev_ktype = { + .sysfs_ops = &nvm_dev_sysfs_ops, + .default_attrs = nvm_dev_default_attrs, + .release = nvm_dev_release +}; + +void nvm_sysfs_unregister_dev(struct nvm_dev *dev) +{ + nvm_sysfs_unregister_grps(dev); + + kobject_del(&dev->kobj); + kobject_put(&dev->kobj); +} + +int nvm_sysfs_register_dev(struct nvm_dev *dev) +{ + int ret; + + dev->kobj.kset = devices; + ret = kobject_init_and_add(&dev->kobj, &nvm_dev_ktype, NULL, "%s", + dev->name); + if (ret < 0) { + pr_err("nvm/sysfs: `_register_dev` failed(%d).\n", ret); + kobject_put(&dev->kobj); + return ret; + } + kobject_uevent(&dev->kobj, KOBJ_ADD); + + ret = nvm_sysfs_register_grps(dev); + if (ret < 0) { + pr_err("nvm/sysfs: `_register_dev` rolling back."); + + kobject_del(&dev->kobj); + kobject_put(&dev->kobj); + + return ret; + } + + return 0; +} + +/* + * Functions for exposing LightNVM devices and targets in sysfs. + * + * They will reside as children of the given `miscdevice`. + */ + +int nvm_sysfs_register(struct miscdevice *miscdev) +{ + devices = kset_create_and_add("devices", NULL, + kobject_get(&miscdev->this_device->kobj)); + if (!devices) + goto devices_err; + + targets = kset_create_and_add("targets", NULL, + kobject_get(&miscdev->this_device->kobj)); + if (!targets) + goto targets_err; + + return 0; + +targets_err: + kobject_put(&miscdev->this_device->kobj); + kset_unregister(devices); +devices_err: + kobject_put(&miscdev->this_device->kobj); + return -ENOMEM; +} + +void nvm_sysfs_unregister(struct miscdevice *miscdev) +{ + kset_unregister(targets); + kset_unregister(devices); +} diff --git a/drivers/lightnvm/sysfs.h b/drivers/lightnvm/sysfs.h new file mode 100644 index 0000000..81e11fe --- /dev/null +++ b/drivers/lightnvm/sysfs.h @@ -0,0 +1,18 @@ +/* + * Functions related to LightNVM sysfs handling. + */ +#ifndef NVM_SYSFS_H_ +#define NVM_SYSFS_H_ + +#include + +int nvm_sysfs_register_target(struct nvm_target *); +void nvm_sysfs_unregister_target(struct nvm_target *); + +int nvm_sysfs_register_dev(struct nvm_dev *); +void nvm_sysfs_unregister_dev(struct nvm_dev *); + +int nvm_sysfs_register(struct miscdevice *); +void nvm_sysfs_unregister(struct miscdevice *); + +#endif /* NVM_SYSFS_H_ */ diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index 5eabdba..bbe3b72 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -174,6 +174,7 @@ struct nvm_id_group { u16 cpar; struct nvm_id_lp_tbl lptbl; + struct kobject kobj; }; struct nvm_addr_format { @@ -205,6 +206,7 @@ struct nvm_target { struct list_head list; struct nvm_tgt_type *type; struct gendisk *disk; + struct kobject kobj; }; struct nvm_tgt_instance { @@ -360,6 +362,8 @@ struct nvm_dev { struct mutex mlock; spinlock_t lock; + + struct kobject kobj; }; static inline struct ppa_addr generic_to_dev_addr(struct nvm_dev *dev, -- 2.5.0