1.. _disk_nvme:
2
3NVMe
4####
5
6NVMe is a standardized logical device interface on PCIe bus exposing storage devices.
7
8NVMe controllers and disks are supported. Disks can be accessed via the :ref:`Disk Access API <disk_access_api>` they expose
9and thus be used through the :ref:`File System API <file_system_api>`.
10
11Driver design
12*************
13
14The driver is sliced up in 3 main parts:
15- NVMe controller :zephyr_file:`drivers/disk/nvme/nvme_controller.c`
16- NVMe commands :zephyr_file:`drivers/disk/nvme/nvme_cmd.c`
17- NVMe namespace :zephyr_file:`drivers/disk/nvme/nvme_namespace.c`
18
19Where the NVMe controller is the root of the device driver. This is the one that will get device driver instances.
20Note that this is only what DTS describes: the NVMe controller, and none of its namespaces (disks).
21The NVMe command is the generic logic used to communicate with the controller and the namespaces it exposes.
22Finally the NVMe namespace is the dedicated part to deal with an actual namespace which, in turn, enables applications
23accessing each ones through the Disk Access API :zephyr_file:`drivers/disk/nvme/nvme_disk.c`.
24
25If a controller exposes more than 1 namespace (disk), it will be possible to raise the amount of built-in namespace support
26by tweaking the configuration option CONFIG_NVME_MAX_NAMESPACES (see below).
27
28Each exposed disk, via it's related disk_info structure, will be distinguished by its name which is inherited from
29it's related namespace. As such, the disk name follows NVMe naming which is nvme<k>n<n> where k is the controller number
30and n the namespame number. Most of the time, if only one NVMe disk is plugged into the system, one will see 'nvme0n0' as
31an exposed disk.
32
33NVMe configuration
34******************
35
36DTS
37===
38
39Any board exposing an NVMe disk should provide a DTS overlay to enable its use within Zephyr
40
41.. code-block:: devicetree
42
43    #include <zephyr/dt-bindings/pcie/pcie.h>
44    / {
45        pcie0 {
46            nvme0: nvme0 {
47                compatible = "nvme-controller";
48                vendor-id = <VENDOR_ID>;
49                device-id = <DEVICE_ID>;
50                status = "okay";
51            };
52        };
53    };
54
55Where VENDOR_ID and DEVICE_ID are the ones from the exposed NVMe controller.
56
57Options
58=======
59
60* :kconfig:option:`CONFIG_NVME`
61
62Note that NVME requires the target to support PCIe multi-vector MSI-X in order to function.
63
64* :kconfig:option:`CONFIG_NVME_MAX_NAMESPACES`
65
66Important note for users
67************************
68
69NVMe specifications mandate the data buffer to be placed in a dword (4 bytes) aligned address.
70While this is not a problem for advanced OS managing virtual memory and dynamic allocations
71below the user processes, this can become an issue in Zephyr as soon as buffer addresses
72map directly to physical memory.
73
74At this stage then, it is up to the user to make sure the buffer address being provided to
75:c:func:`disk_access_read` and :c:func:`disk_access_write` are dword aligned.
76