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.
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.
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.