2
0
mirror of https://git.missingno.dev/kolibrios-nvme-driver/ synced 2024-12-23 06:18:47 +01:00

nvme_init: check MQES

This commit is contained in:
Abdur-Rahman Mansoor 2024-06-27 19:19:06 -04:00
parent 274a5681a2
commit 76f94d74e1

View File

@ -449,7 +449,8 @@ proc nvme_write stdcall, pci:dword, qid:word, nsid:dword, dptr:dword, slba:qword
; TODO: Use IDENTC.NOIOB to construct read/write commands that don't ; TODO: Use IDENTC.NOIOB to construct read/write commands that don't
; cross the I/O boundary to achieve optimal performance ; cross the I/O boundary to achieve optimal performance
; Also add DPTR/MPTR ;
; Read AWUN/NAWUN
sub esp, sizeof.SQ_ENTRY sub esp, sizeof.SQ_ENTRY
stdcall memset, esp, 0, sizeof.SQ_ENTRY stdcall memset, esp, 0, sizeof.SQ_ENTRY
movzx ecx, [qid] movzx ecx, [qid]
@ -461,7 +462,7 @@ proc nvme_write stdcall, pci:dword, qid:word, nsid:dword, dptr:dword, slba:qword
mov dword [esp + SQ_ENTRY.nsid], eax mov dword [esp + SQ_ENTRY.nsid], eax
mov eax, dword [slba] mov eax, dword [slba]
mov dword [esp + SQ_ENTRY.cdw10], eax mov dword [esp + SQ_ENTRY.cdw10], eax
mov eax, dword [slba + 4] mov eax, 0 ; SLBA + 32 (fix later)
mov dword [esp + SQ_ENTRY.cdw11], eax mov dword [esp + SQ_ENTRY.cdw11], eax
movzx eax, [nlb] movzx eax, [nlb]
mov word [esp + SQ_ENTRY.cdw12], ax mov word [esp + SQ_ENTRY.cdw12], ax
@ -604,6 +605,11 @@ proc nvme_init stdcall, pci:dword
DEBUGF DBG_INFO, "(NVMe) CSTS: 0x%x\n", eax DEBUGF DBG_INFO, "(NVMe) CSTS: 0x%x\n", eax
end if end if
; check maximum queue entries supported
mov ax, word [edi + NVME_MMIO.CAP]
cmp ax, SQ_ENTRIES
jl .exit_fail
; For some reason, bit 7 (No I/O command set supported) is also set to 1 despite bit 0 (NVM command set) ; For some reason, bit 7 (No I/O command set supported) is also set to 1 despite bit 0 (NVM command set)
; being set to 1.. so I am not sure if bit 7 should be checked at all.. investigate later. ; being set to 1.. so I am not sure if bit 7 should be checked at all.. investigate later.
mov eax, dword [edi + NVME_MMIO.CAP + 4] mov eax, dword [edi + NVME_MMIO.CAP + 4]
@ -763,11 +769,11 @@ proc nvme_init stdcall, pci:dword
mov eax, dword [esi + NVM_QUEUE_ENTRY.cq_ptr] mov eax, dword [esi + NVM_QUEUE_ENTRY.cq_ptr]
invoke GetPhysAddr invoke GetPhysAddr
stdcall create_io_completion_queue, [pci], eax, 1, IEN_ON stdcall create_io_completion_queue, [pci], eax, 1, IEN_ON
DEBUGF DBG_INFO, "nvme%u: Successfully created I/O completion queue 1", [edi + pcidev.num] DEBUGF DBG_INFO, "nvme%u: Successfully created I/O completion queue 1\n", [edi + pcidev.num]
mov eax, dword [esi + NVM_QUEUE_ENTRY.sq_ptr] mov eax, dword [esi + NVM_QUEUE_ENTRY.sq_ptr]
invoke GetPhysAddr invoke GetPhysAddr
stdcall create_io_submission_queue, [pci], eax, 1, 1 stdcall create_io_submission_queue, [pci], eax, 1, 1
DEBUGF DBG_INFO, "nvme%u: Successfully created I/O submission queue 1", [edi + pcidev.num] DEBUGF DBG_INFO, "nvme%u: Successfully created I/O submission queue 1\n", [edi + pcidev.num]
if 1 if 1
stdcall determine_active_nsids, [pci] stdcall determine_active_nsids, [pci]
@ -816,8 +822,12 @@ proc nvme_init stdcall, pci:dword
DEBUGF DBG_INFO, "nvme%un%u: Namespace LBA Data Size: %u\n", [esi + pcidev.num], [esi + pcidev.nsid], eax DEBUGF DBG_INFO, "nvme%un%u: Namespace LBA Data Size: %u\n", [esi + pcidev.num], [esi + pcidev.nsid], eax
invoke KernelFree, edi invoke KernelFree, edi
mov eax, test_string ;mov eax, test_string
stdcall nvme_write, [pci], 1, [esi + pcidev.nsid], eax, 0, 1 invoke KernelAlloc, 0x1000
test eax, eax
jz .exit_fail
invoke GetPhysAddr
stdcall nvme_write, [pci], 1, [esi + pcidev.nsid], eax, 1, 1
DEBUGF DBG_INFO, "nvme%u: Successfully initialized driver\n", [esi + pcidev.num] DEBUGF DBG_INFO, "nvme%u: Successfully initialized driver\n", [esi + pcidev.num]
xor eax, eax xor eax, eax
inc eax inc eax