zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.83k stars 6.6k forks source link

NVMe zephyr support with RISCV #76308

Open naveen-i-s opened 3 months ago

naveen-i-s commented 3 months ago

QEMU : emulator version 7.2.92, qemu-system-riscv64 binary. zephyr version : 3.6.0 Command used to launch NVMe : qemu-system-riscv64 -kernel ./zephyr/zephyr.elf -nographic -machine virt -m 512 -device pcie-root-port,id=root_port1 -device nvme,drive=nvme0,serial=deadbeaf1 -drive file=nvme.img,if=none,id=nvme0 -bios none

Background of the issue : I was trying to utilize zephyr NVMe driver with Qemu-Riscv emulated NVMe device using gpex-root support for pcie. Everything goes well until it got stuck while trying to enable the NVMe controller. It fails with timeout error. Below is the error log:

After debugging, NVMe mmio operations were failing for each of the read/write. I found that PCI expects PCI_COMMAND_MEMORY command to update the bar address mapping. I checked that there is no such command being sent in zephyr pci/NVMe driver. After fixing the same with pci_command_memory, NVMe controller has been enabled and working.

Solution proposed/worked : _- pcie_set_cmd(bdf, PCIE_CONF_CMDSTATMASTER, true); + pcie_set_cmd(bdf, PCIE_CONF_CMDSTAT_MEM | PCIE_CONF_CMDSTAT_MASTER, true);

Adding PCIE_CONF_CMDSTAT_MEM command to set the mapping bar address in pci under qemu device. It is already being done in pci driver for type1 device only, It should also be done for type0. Above change is done in "zephyr/drivers/pcie/host/msi.c" file under pcie_msi_enable API. It can be done as part of NVMe driver for type0 device.

### Tasks
github-actions[bot] commented 3 months ago

Hi @naveen-i-s! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙