1*83d290c5STom Rini# SPDX-License-Identifier: GPL-2.0+ 2982388eaSZhikang Zhang# 3982388eaSZhikang Zhang# Copyright (C) 2017 NXP Semiconductors 4982388eaSZhikang Zhang# Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com> 5982388eaSZhikang Zhang 6982388eaSZhikang ZhangWhat is NVMe 7982388eaSZhikang Zhang============ 8982388eaSZhikang Zhang 9982388eaSZhikang ZhangNVM Express (NVMe) is a register level interface that allows host software to 10982388eaSZhikang Zhangcommunicate with a non-volatile memory subsystem. This interface is optimized 11982388eaSZhikang Zhangfor enterprise and client solid state drives, typically attached to the PCI 12982388eaSZhikang Zhangexpress interface. It is a scalable host controller interface designed to 13982388eaSZhikang Zhangaddress the needs of enterprise and client systems that utilize PCI express 14982388eaSZhikang Zhangbased solid state drives (SSD). The interface provides optimized command 15982388eaSZhikang Zhangsubmission and completion paths. It includes support for parallel operation by 16982388eaSZhikang Zhangsupporting up to 64K I/O queues with up to 64K commands per I/O queue. 17982388eaSZhikang Zhang 18982388eaSZhikang ZhangThe device is comprised of some number of controllers, where each controller 19982388eaSZhikang Zhangis comprised of some number of namespaces, where each namespace is comprised 20982388eaSZhikang Zhangof some number of logical blocks. A namespace is a quantity of non-volatile 21982388eaSZhikang Zhangmemory that is formatted into logical blocks. An NVMe namespace is equivalent 22982388eaSZhikang Zhangto a SCSI LUN. Each namespace is operated as an independent "device". 23982388eaSZhikang Zhang 24982388eaSZhikang ZhangHow it works 25982388eaSZhikang Zhang------------ 26982388eaSZhikang ZhangThere is an NVMe uclass driver (driver name "nvme"), an NVMe host controller 27982388eaSZhikang Zhangdriver (driver name "nvme") and an NVMe namespace block driver (driver name 28982388eaSZhikang Zhang"nvme-blk"). The host controller driver is supposed to probe the hardware and 29982388eaSZhikang Zhangdo necessary initialization to put the controller into a ready state at which 30982388eaSZhikang Zhangit is able to scan all available namespaces attached to it. Scanning namespace 31982388eaSZhikang Zhangis triggered by the NVMe uclass driver and the actual work is done in the NVMe 32982388eaSZhikang Zhangnamespace block driver. 33982388eaSZhikang Zhang 34982388eaSZhikang ZhangStatus 35982388eaSZhikang Zhang------ 36982388eaSZhikang ZhangIt only support basic block read/write functions in the NVMe driver. 37982388eaSZhikang Zhang 38982388eaSZhikang ZhangConfig options 39982388eaSZhikang Zhang-------------- 40982388eaSZhikang ZhangCONFIG_NVME Enable NVMe device support 410adc38beSZhikang ZhangCONFIG_CMD_NVME Enable basic NVMe commands 420adc38beSZhikang Zhang 430adc38beSZhikang ZhangUsage in U-Boot 440adc38beSZhikang Zhang--------------- 450adc38beSZhikang ZhangTo use an NVMe hard disk from U-Boot shell, a 'nvme scan' command needs to 460adc38beSZhikang Zhangbe executed for all NVMe hard disks attached to the NVMe controller to be 470adc38beSZhikang Zhangidentified. 480adc38beSZhikang Zhang 490adc38beSZhikang ZhangTo list all of the NVMe hard disks, try: 500adc38beSZhikang Zhang 51fceadc14SBin Meng => nvme info 520adc38beSZhikang Zhang Device 0: Vendor: 0x8086 Rev: 8DV10131 Prod: CVFT535600LS400BGN 530adc38beSZhikang Zhang Type: Hard Disk 540adc38beSZhikang Zhang Capacity: 381554.0 MB = 372.6 GB (781422768 x 512) 550adc38beSZhikang Zhang 560adc38beSZhikang Zhangand print out detailed information for controller and namespaces via: 570adc38beSZhikang Zhang 58fceadc14SBin Meng => nvme detail 590adc38beSZhikang Zhang 600adc38beSZhikang ZhangRaw block read/write to can be done via the 'nvme read/write' commands: 610adc38beSZhikang Zhang 620adc38beSZhikang Zhang => nvme read a0000000 0 11000 630adc38beSZhikang Zhang 640adc38beSZhikang Zhang => tftp 80000000 /tftpboot/kernel.itb 650adc38beSZhikang Zhang => nvme write 80000000 0 11000 660adc38beSZhikang Zhang 670adc38beSZhikang ZhangOf course, file system command can be used on the NVMe hard disk as well: 680adc38beSZhikang Zhang 690adc38beSZhikang Zhang => fatls nvme 0:1 700adc38beSZhikang Zhang 32376967 kernel.itb 710adc38beSZhikang Zhang 22929408 100m 720adc38beSZhikang Zhang 730adc38beSZhikang Zhang 2 file(s), 0 dir(s) 740adc38beSZhikang Zhang 750adc38beSZhikang Zhang => fatload nvme 0:1 a0000000 /kernel.itb 760adc38beSZhikang Zhang => bootm a0000000 777088a365SBin Meng 787088a365SBin MengTesting NVMe with QEMU x86 797088a365SBin Meng-------------------------- 807088a365SBin MengQEMU supports NVMe emulation and we can test NVMe driver with QEMU x86 running 817088a365SBin MengU-Boot. Please see README.x86 for how to build u-boot.rom image for QEMU x86. 827088a365SBin Meng 837088a365SBin MengExample command line to call QEMU x86 below with emulated NVMe device: 847088a365SBin Meng$ ./qemu-system-i386 -drive file=nvme.img,if=none,id=drv0 -device nvme,drive=drv0,serial=QEMUNVME0001 -bios u-boot.rom 85