![]() |
RT-Thread RTOS
An open source embedded real-time operating system
|
**RT_USING_NVME** builds the protocol core (**nvme.c**) and optionally **nvme-pci.c** (**RT_NVME_PCI**). Controllers register with **rt_nvme_controller_register**; each namespace becomes a **rt_blk_disk** for the block layer.
Controller API and queue ops: NVMe subsystem.
Sources: **components/drivers/nvme/nvme.c**, **nvme-pci.c**, **components/drivers/include/drivers/nvme.h**.
| Option | Depends on | Role |
|---|---|---|
**RT_USING_NVME** | **RT_USING_DM**, **RT_USING_BLK**, **RT_USING_DMA** | Core stack |
**RT_USING_NVME_IO_QUEUE** | **RT_USING_NVME** | Number of I/O queues (2/4/8 by priority profile) |
**RT_NVME_PCI** | **RT_USING_NVME**, **RT_USING_PCI** | PCI function driver (default y) |
**SOC_DM_NVME_DIR** | BSP | Extra non-PCI controllers |
**RT_USING_NVME_QUEUE** in **nvme.h** is **1 + RT_USING_NVME_IO_QUEUE * RT_CPUS_NR** (admin + per-CPU IO slots).
Any NVMe class PCI function binds **nvme-pci** driver.
rt_nvme_controller_unregister**rt_pci_clear_master**, **rt_iounmap(regs)**, free **pci_nvme_controller****pdev->id->data** may point to **struct pci_nvme_quirk** with alternate **rt_nvme_ops** (vendor MMIO). Default uses standard doorbell path in **nvme.c**.
| Mode | Behavior |
|---|---|
| MSI-X | Up to **RT_USING_NVME_QUEUE** vectors; linear index mapping |
| INTx | **irqs_nr = 1**, shared line — rely on **complete_cmd** to disambiguate if needed |
**INIT_SECONDARY_CPU_EXPORT(nvme_queue_affinify_fixup)** (in **nvme.c**):
i ≡ cpuid (mod RT_CPUS_NR)**, sets IRQ affinity to that CPU via **rt_pic_irq_set_affinity**numa=on** — keep queue IRQ near memory nodeAssign **nvme->irqs[]** before **rt_nvme_controller_register** — core wires ISR per queue during setup.
Queue rings allocated with **rt_dma_alloc(nvme->dev, ...)** and **nvme_queue_dma_flags()** (coherent / device attributes per **dev**).
Identify buffers use **rt_malloc_align(..., nvme->page_size)** after page size is negotiated from **CAP.MPSMIN/MAX**.
After Identify NS:
Partitions use standard **RT_BLK_PARTITION_MAX** — see disk/partitions docs if enabled in BSP.
regs**, implement **struct rt_nvme_ops** ( **setup_queue/submit_cmd/complete_cmd** as needed).irqs[]** for admin + IO queues.nvme->dev** to the **rt_device** used for DMA mapping.rt_nvme_controller_register**.SOC_DM_NVME_DIR** and platform/PCIe-alt probe.RT_USING_DM**, **RT_USING_PCI**, **RT_USING_BLK**, **RT_USING_DMA**, **RT_USING_NVME**, **RT_NVME_PCI**.rt_pci_set_master** path runs (done in **pci_nvme_probe**).numa=on** + CPU/memory **numa-node-id** in DT (NUMA helpers).nvme0n1** (etc.) and partition mount if used.| Issue | Mitigation |
|---|---|
| BAR not mapped | **rt_pci_iomap** failure → probe abort |
| MSI-X vector shortage | Falls back to INTx — may need **complete_cmd** |
**CSTS == -1** | Usually bad BAR/endianness — register rejects early |
Inverted setup_queue success | NVMe subsystem — match **nvme.c** polarity |
| Secondary CPU IRQ affinity | Ensure **nvme_queue_affinify_fixup** runs (SMP BSP) |
components/drivers/nvme/Kconfig