1*4882a593Smuzhiyun# 2*4882a593Smuzhiyun# Copyright (C) 2017 NXP Semiconductors 3*4882a593Smuzhiyun# Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com> 4*4882a593Smuzhiyun# 5*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0+ 6*4882a593Smuzhiyun# 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunWhat is NVMe 9*4882a593Smuzhiyun============ 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunNVM Express (NVMe) is a register level interface that allows host software to 12*4882a593Smuzhiyuncommunicate with a non-volatile memory subsystem. This interface is optimized 13*4882a593Smuzhiyunfor enterprise and client solid state drives, typically attached to the PCI 14*4882a593Smuzhiyunexpress interface. It is a scalable host controller interface designed to 15*4882a593Smuzhiyunaddress the needs of enterprise and client systems that utilize PCI express 16*4882a593Smuzhiyunbased solid state drives (SSD). The interface provides optimized command 17*4882a593Smuzhiyunsubmission and completion paths. It includes support for parallel operation by 18*4882a593Smuzhiyunsupporting up to 64K I/O queues with up to 64K commands per I/O queue. 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunThe device is comprised of some number of controllers, where each controller 21*4882a593Smuzhiyunis comprised of some number of namespaces, where each namespace is comprised 22*4882a593Smuzhiyunof some number of logical blocks. A namespace is a quantity of non-volatile 23*4882a593Smuzhiyunmemory that is formatted into logical blocks. An NVMe namespace is equivalent 24*4882a593Smuzhiyunto a SCSI LUN. Each namespace is operated as an independent "device". 25*4882a593Smuzhiyun 26*4882a593SmuzhiyunHow it works 27*4882a593Smuzhiyun------------ 28*4882a593SmuzhiyunThere is an NVMe uclass driver (driver name "nvme"), an NVMe host controller 29*4882a593Smuzhiyundriver (driver name "nvme") and an NVMe namespace block driver (driver name 30*4882a593Smuzhiyun"nvme-blk"). The host controller driver is supposed to probe the hardware and 31*4882a593Smuzhiyundo necessary initialization to put the controller into a ready state at which 32*4882a593Smuzhiyunit is able to scan all available namespaces attached to it. Scanning namespace 33*4882a593Smuzhiyunis triggered by the NVMe uclass driver and the actual work is done in the NVMe 34*4882a593Smuzhiyunnamespace block driver. 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunStatus 37*4882a593Smuzhiyun------ 38*4882a593SmuzhiyunIt only support basic block read/write functions in the NVMe driver. 39*4882a593Smuzhiyun 40*4882a593SmuzhiyunConfig options 41*4882a593Smuzhiyun-------------- 42*4882a593SmuzhiyunCONFIG_NVME Enable NVMe device support 43*4882a593SmuzhiyunCONFIG_CMD_NVME Enable basic NVMe commands 44*4882a593Smuzhiyun 45*4882a593SmuzhiyunUsage in U-Boot 46*4882a593Smuzhiyun--------------- 47*4882a593SmuzhiyunTo use an NVMe hard disk from U-Boot shell, a 'nvme scan' command needs to 48*4882a593Smuzhiyunbe executed for all NVMe hard disks attached to the NVMe controller to be 49*4882a593Smuzhiyunidentified. 50*4882a593Smuzhiyun 51*4882a593SmuzhiyunTo list all of the NVMe hard disks, try: 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun => nvme info 54*4882a593Smuzhiyun Device 0: Vendor: 0x8086 Rev: 8DV10131 Prod: CVFT535600LS400BGN 55*4882a593Smuzhiyun Type: Hard Disk 56*4882a593Smuzhiyun Capacity: 381554.0 MB = 372.6 GB (781422768 x 512) 57*4882a593Smuzhiyun 58*4882a593Smuzhiyunand print out detailed information for controller and namespaces via: 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun => nvme detail 61*4882a593Smuzhiyun 62*4882a593SmuzhiyunRaw block read/write to can be done via the 'nvme read/write' commands: 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun => nvme read a0000000 0 11000 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun => tftp 80000000 /tftpboot/kernel.itb 67*4882a593Smuzhiyun => nvme write 80000000 0 11000 68*4882a593Smuzhiyun 69*4882a593SmuzhiyunOf course, file system command can be used on the NVMe hard disk as well: 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun => fatls nvme 0:1 72*4882a593Smuzhiyun 32376967 kernel.itb 73*4882a593Smuzhiyun 22929408 100m 74*4882a593Smuzhiyun 75*4882a593Smuzhiyun 2 file(s), 0 dir(s) 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun => fatload nvme 0:1 a0000000 /kernel.itb 78*4882a593Smuzhiyun => bootm a0000000 79*4882a593Smuzhiyun 80*4882a593SmuzhiyunTesting NVMe with QEMU x86 81*4882a593Smuzhiyun-------------------------- 82*4882a593SmuzhiyunQEMU supports NVMe emulation and we can test NVMe driver with QEMU x86 running 83*4882a593SmuzhiyunU-Boot. Please see README.x86 for how to build u-boot.rom image for QEMU x86. 84*4882a593Smuzhiyun 85*4882a593SmuzhiyunExample command line to call QEMU x86 below with emulated NVMe device: 86*4882a593Smuzhiyun$ ./qemu-system-i386 -drive file=nvme.img,if=none,id=drv0 -device nvme,drive=drv0,serial=QEMUNVME0001 -bios u-boot.rom 87