summaryrefslogtreecommitdiff
path: root/Kernel/Storage/NVMe
diff options
context:
space:
mode:
authorPankaj Raghav <pankydev8@gmail.com>2022-01-16 09:58:59 +0530
committerIdan Horowitz <idan.horowitz@gmail.com>2022-01-18 11:37:04 +0200
commitba7846647cfa765e21845c015612d8d898ec5768 (patch)
treec03be1d5a0b6cc1e37ef38c0df596e8479ee6294 /Kernel/Storage/NVMe
parent3441eac960e20f84e56c4a8b35d28befb214c2ed (diff)
downloadserenity-ba7846647cfa765e21845c015612d8d898ec5768.zip
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.
Diffstat (limited to 'Kernel/Storage/NVMe')
-rw-r--r--Kernel/Storage/NVMe/NVMeController.cpp4
1 files changed, 2 insertions, 2 deletions
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<void> NVMeController::initialize()
m_controller_regs = TRY(Memory::map_typed_writable<volatile ControllerRegister>(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<void> 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) {