From ba7846647cfa765e21845c015612d8d898ec5768 Mon Sep 17 00:00:00 2001 From: Pankaj Raghav Date: Sun, 16 Jan 2022 09:58:59 +0530 Subject: Kernel: Fix m_ready_timeout calculation in NVMe The CAP.TO is 0 based. Even though I don't see that mentioned in the spec explicitly, all major OSs such as Linux, FreeBSD add 1 to the CAP.TO while calculating the timeout. --- Kernel/Storage/NVMe/NVMeController.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Kernel/Storage/NVMe') diff --git a/Kernel/Storage/NVMe/NVMeController.cpp b/Kernel/Storage/NVMe/NVMeController.cpp index 602f4f81d5..ad72ac2c9f 100644 --- a/Kernel/Storage/NVMe/NVMeController.cpp +++ b/Kernel/Storage/NVMe/NVMeController.cpp @@ -48,7 +48,7 @@ UNMAP_AFTER_INIT ErrorOr NVMeController::initialize() m_controller_regs = TRY(Memory::map_typed_writable(PhysicalAddress(m_bar))); auto caps = m_controller_regs->cap; - m_ready_timeout = Time::from_milliseconds(CAP_TO(caps) * 500); // CAP.TO is in 500ms units + m_ready_timeout = Time::from_milliseconds((CAP_TO(caps) + 1) * 500); // CAP.TO is in 500ms units calculate_doorbell_stride(); TRY(create_admin_queue(irq)); @@ -69,7 +69,7 @@ UNMAP_AFTER_INIT ErrorOr NVMeController::initialize() bool NVMeController::wait_for_ready(bool expected_ready_bit_value) { static constexpr size_t one_ms_io_delay = 1000; - auto wait_iterations = max(1, m_ready_timeout.to_milliseconds()); + auto wait_iterations = m_ready_timeout.to_milliseconds(); u32 expected_rdy = expected_ready_bit_value ? 1 : 0; while (((m_controller_regs->csts >> CSTS_RDY_BIT) & 0x1) != expected_rdy) { -- cgit v1.2.3