mirror of
https://git.missingno.dev/kolibrios-nvme-driver/
synced 2025-01-31 01:30:05 +01:00
important bug fix and some micro optimizations
As for the fix, the submission queues weren't properly being zeroed out due to a small typo. The other stuff has some commented out stuff that I'm currently debugging and working on.
This commit is contained in:
parent
a88a44c627
commit
534103061c
@ -972,7 +972,7 @@ proc nvme_init stdcall, pci:dword
|
|||||||
jz .exit_fail
|
jz .exit_fail
|
||||||
mov dword [edi + ecx + NVM_QUEUE_ENTRY.sq_ptr], eax
|
mov dword [edi + ecx + NVM_QUEUE_ENTRY.sq_ptr], eax
|
||||||
push ecx
|
push ecx
|
||||||
stdcall memsetdz, eax, sizeof.CQ_ENTRY * CQ_ENTRIES / 4
|
stdcall memsetdz, eax, sizeof.SQ_ENTRY * SQ_ENTRIES / 4
|
||||||
invoke CreateRingBuffer, 0x1000, PG_SW
|
invoke CreateRingBuffer, 0x1000, PG_SW
|
||||||
pop ecx
|
pop ecx
|
||||||
test eax, eax
|
test eax, eax
|
||||||
@ -989,23 +989,19 @@ proc nvme_init stdcall, pci:dword
|
|||||||
mov dword [edi + ecx + NVM_QUEUE_ENTRY.cmd_ptr], eax
|
mov dword [edi + ecx + NVM_QUEUE_ENTRY.cmd_ptr], eax
|
||||||
mov esi, eax
|
mov esi, eax
|
||||||
push ecx
|
push ecx
|
||||||
xor ecx, ecx
|
xor ebx, ebx
|
||||||
|
|
||||||
.init_cmd_entries:
|
.init_cmd_entries:
|
||||||
push ecx
|
|
||||||
; BUG: Won't pop ecx if allocation fails
|
; BUG: Won't pop ecx if allocation fails
|
||||||
invoke KernelAlloc, sizeof.MUTEX
|
invoke KernelAlloc, sizeof.MUTEX
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .exit_fail
|
jz .exit_fail
|
||||||
pop ecx
|
mov dword [esi + ebx * NVMQCMD.mutex_ptr], eax
|
||||||
mov dword [esi + ecx * NVMQCMD.mutex_ptr], eax
|
mov dword [esi + ebx * NVMQCMD.cid], ebx
|
||||||
mov dword [esi + ecx * NVMQCMD.cid], ecx
|
|
||||||
push ecx
|
|
||||||
mov ecx, eax
|
mov ecx, eax
|
||||||
invoke MutexInit
|
invoke MutexInit
|
||||||
pop ecx
|
inc ebx
|
||||||
inc ecx
|
cmp ebx, CQ_ENTRIES
|
||||||
cmp ecx, CQ_ENTRIES
|
|
||||||
jne .init_cmd_entries
|
jne .init_cmd_entries
|
||||||
|
|
||||||
pop ecx
|
pop ecx
|
||||||
@ -1108,7 +1104,7 @@ proc nvme_init stdcall, pci:dword
|
|||||||
jnz .exit_fail
|
jnz .exit_fail
|
||||||
|
|
||||||
; Create I/O Queues
|
; Create I/O Queues
|
||||||
; (TODO: create N queue pairs for N CPU cores, see page 8 of NVMe 1.4 spec for an explaination
|
; (TODO: create N queue pairs for N CPU cores, see page 8 of NVMe 1.4 spec for an explaination)
|
||||||
mov esi, [pci]
|
mov esi, [pci]
|
||||||
mov edi, esi
|
mov edi, esi
|
||||||
mov esi, dword [esi + pcidev.queue_entries]
|
mov esi, dword [esi + pcidev.queue_entries]
|
||||||
@ -1215,13 +1211,11 @@ endp
|
|||||||
|
|
||||||
proc get_new_cid stdcall, pci:dword, y:dword
|
proc get_new_cid stdcall, pci:dword, y:dword
|
||||||
|
|
||||||
push esi
|
mov eax, [pci]
|
||||||
mov esi, [pci]
|
mov eax, dword [eax + pcidev.queue_entries]
|
||||||
mov esi, [esi + pcidev.queue_entries]
|
|
||||||
mov ecx, [y]
|
mov ecx, [y]
|
||||||
imul ecx, sizeof.NVM_QUEUE_ENTRY
|
imul ecx, sizeof.NVM_QUEUE_ENTRY
|
||||||
movzx eax, word [esi + ecx + NVM_QUEUE_ENTRY.tail]
|
movzx eax, word [eax + ecx + NVM_QUEUE_ENTRY.head]
|
||||||
pop esi
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
endp
|
endp
|
||||||
@ -1316,7 +1310,7 @@ proc cqyhdbl_write stdcall, pci:dword, y:dword, cqh:dword
|
|||||||
lea edi, dword [edi + ecx]
|
lea edi, dword [edi + ecx]
|
||||||
mov esi, dword [esi + pcidev.io_addr]
|
mov esi, dword [esi + pcidev.io_addr]
|
||||||
mov eax, [cqh]
|
mov eax, [cqh]
|
||||||
;DEBUGF DBG_INFO, "Writing to completion queue doorbell register: %u\n", ax
|
;DEBUGF DBG_INFO, "Writing to completion queue doorbell register 0x%x: %u\n", edx, ax
|
||||||
mov word [esi + edx], ax ; Write to CQyHDBL
|
mov word [esi + edx], ax ; Write to CQyHDBL
|
||||||
mov word [edi + NVM_QUEUE_ENTRY.head], ax
|
mov word [edi + NVM_QUEUE_ENTRY.head], ax
|
||||||
pop edi esi
|
pop edi esi
|
||||||
@ -1332,13 +1326,18 @@ proc sqytdbl_write stdcall, pci:dword, y:word, cmd:dword
|
|||||||
mov edi, dword [edi + pcidev.queue_entries]
|
mov edi, dword [edi + pcidev.queue_entries]
|
||||||
movzx ecx, [y]
|
movzx ecx, [y]
|
||||||
imul ecx, sizeof.NVM_QUEUE_ENTRY
|
imul ecx, sizeof.NVM_QUEUE_ENTRY
|
||||||
|
;mov eax, dword [edi + ecx + NVM_QUEUE_ENTRY.cmd_ptr]
|
||||||
mov edi, dword [edi + ecx + NVM_QUEUE_ENTRY.sq_ptr]
|
mov edi, dword [edi + ecx + NVM_QUEUE_ENTRY.sq_ptr]
|
||||||
mov esi, [cmd]
|
mov esi, [cmd]
|
||||||
mov ecx, dword [esi + SQ_ENTRY.cdw0]
|
mov ecx, dword [esi + SQ_ENTRY.cdw0]
|
||||||
shr ecx, 16 ; Get CID
|
shr ecx, 16 ; Get CID
|
||||||
imul ecx, sizeof.SQ_ENTRY
|
imul ecx, sizeof.SQ_ENTRY
|
||||||
lea edi, [edi + ecx]
|
lea edi, [edi + ecx]
|
||||||
|
;mov ecx, [eax + ecx + NVMQCMD.mutex_ptr]
|
||||||
|
;push ecx
|
||||||
stdcall memcpy, edi, esi, sizeof.SQ_ENTRY
|
stdcall memcpy, edi, esi, sizeof.SQ_ENTRY
|
||||||
|
;pop ecx
|
||||||
|
;invoke MutexLock
|
||||||
|
|
||||||
mov edi, [pci]
|
mov edi, [pci]
|
||||||
mov esi, dword [edi + pcidev.io_addr]
|
mov esi, dword [edi + pcidev.io_addr]
|
||||||
@ -1419,9 +1418,9 @@ proc consume_cq_entries stdcall, pci:dword, queue:dword
|
|||||||
mov edi, dword [esi + NVM_QUEUE_ENTRY.cq_ptr]
|
mov edi, dword [esi + NVM_QUEUE_ENTRY.cq_ptr]
|
||||||
movzx eax, word [esi + NVM_QUEUE_ENTRY.tail]
|
movzx eax, word [esi + NVM_QUEUE_ENTRY.tail]
|
||||||
movzx ecx, word [esi + NVM_QUEUE_ENTRY.head]
|
movzx ecx, word [esi + NVM_QUEUE_ENTRY.head]
|
||||||
stdcall is_queue_full, eax, ecx
|
;stdcall is_queue_full, eax, ecx
|
||||||
test eax, eax
|
;test eax, eax
|
||||||
jnz .end
|
;jnz .end
|
||||||
movzx ecx, word [esi + NVM_QUEUE_ENTRY.head]
|
movzx ecx, word [esi + NVM_QUEUE_ENTRY.head]
|
||||||
cmp ecx, (NVM_ACQS - 1)
|
cmp ecx, (NVM_ACQS - 1)
|
||||||
jb .loop
|
jb .loop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user