mirror of
https://git.missingno.dev/kolibrios-nvme-driver/
synced 2024-11-09 18:10:33 +01:00
fix nvme_cleanup and add more debugging logs
This removes the memory allocation in nvme_cleanup as well. Since that was causing problems at shutdown, for some reason. But now it does correctly shutdown the controller.
This commit is contained in:
parent
39ad8d2f3a
commit
408a1c7f30
@ -42,7 +42,7 @@ ends
|
||||
proc START c, reason:dword, cmdline:dword
|
||||
local AnythingLoadedSuccessfully db 0
|
||||
|
||||
push esi edi
|
||||
push ebx esi edi
|
||||
cmp [reason], DRV_ENTRY
|
||||
jne .err
|
||||
|
||||
@ -82,12 +82,12 @@ local AnythingLoadedSuccessfully db 0
|
||||
cmp [AnythingLoadedSuccessfully], 0
|
||||
jz .err
|
||||
invoke RegService, my_service, service_proc
|
||||
pop edi esi
|
||||
pop edi esi ebx
|
||||
ret
|
||||
|
||||
.err:
|
||||
;call nvme_cleanup
|
||||
pop edi esi
|
||||
call nvme_cleanup
|
||||
pop edi esi ebx
|
||||
ret
|
||||
|
||||
endp
|
||||
@ -553,6 +553,7 @@ proc detect_nvme
|
||||
jz .err
|
||||
mov dword [p_nvme_devices], eax
|
||||
mov dword [esi + PCIDEV.owner], eax
|
||||
DEBUGF DBG_INFO, "nvme: Allocated memory for PCI devices at: 0x%x\n", eax
|
||||
|
||||
@@:
|
||||
mov ecx, dword [pcidevs_len]
|
||||
@ -738,6 +739,7 @@ proc nvme_init stdcall, pci:dword
|
||||
invoke KernelAlloc, QUEUE_ALLOC_SIZE
|
||||
test eax, eax
|
||||
jz .exit_fail
|
||||
DEBUGF DBG_INFO, "nvme%u: Allocated queue at offset %u: 0x%x\n", [esi + pcidev.num], ebx, eax
|
||||
mov dword [edi + ebx + NVM_QUEUE_ENTRY.cq_ptr], eax
|
||||
mov edx, eax
|
||||
add eax, CQ_ALLOC_SIZE
|
||||
@ -749,8 +751,8 @@ proc nvme_init stdcall, pci:dword
|
||||
test eax, eax
|
||||
jz .exit_fail
|
||||
mov dword [edi + ebx + NVM_QUEUE_ENTRY.cmd_ptr], eax
|
||||
push ebx esi
|
||||
mov esi, eax
|
||||
push ebx
|
||||
xor ebx, ebx
|
||||
|
||||
.init_cmd_entries:
|
||||
@ -766,7 +768,7 @@ proc nvme_init stdcall, pci:dword
|
||||
cmp ebx, CQ_ENTRIES
|
||||
jne .init_cmd_entries
|
||||
|
||||
pop ebx
|
||||
pop esi ebx
|
||||
add ebx, sizeof.NVM_QUEUE_ENTRY
|
||||
cmp ebx, (LAST_QUEUE_ID + 1) * sizeof.NVM_QUEUE_ENTRY
|
||||
jne .init_queues
|
||||
@ -969,7 +971,7 @@ proc nvme_init stdcall, pci:dword
|
||||
ret
|
||||
|
||||
.exit_fail_cleanup:
|
||||
pop eax
|
||||
add esp, 8
|
||||
|
||||
.exit_fail:
|
||||
mov esi, [pci]
|
||||
@ -1252,15 +1254,16 @@ endp
|
||||
|
||||
proc nvme_cleanup
|
||||
|
||||
DEBUGF DBG_INFO, "nvme_cleanup called\n"
|
||||
push ebx esi edi
|
||||
mov esi, dword [p_nvme_devices]
|
||||
test esi, esi
|
||||
jnz @f
|
||||
pop edi esi ebx
|
||||
ret
|
||||
|
||||
@@:
|
||||
mov ebx, dword [pcidevs_len]
|
||||
sub esi, sizeof.pcidev
|
||||
xor ebx, ebx
|
||||
|
||||
.get_pcidev:
|
||||
add esi, sizeof.pcidev
|
||||
@ -1268,51 +1271,28 @@ proc nvme_cleanup
|
||||
; Free the queues
|
||||
mov edi, dword [esi + pcidev.queue_entries]
|
||||
test edi, edi
|
||||
jz .free_pcidevs
|
||||
jz .ret
|
||||
sub edi, sizeof.NVM_QUEUE_ENTRY
|
||||
xor ecx, ecx
|
||||
push ebx
|
||||
xor ebx, ebx
|
||||
|
||||
.get_queue:
|
||||
add edi, sizeof.NVM_QUEUE_ENTRY
|
||||
|
||||
; TODO: Check if I/O completion and submission queue exist
|
||||
; before deleting?
|
||||
push ecx
|
||||
test ecx, ecx
|
||||
test ebx, ebx
|
||||
jz @f ; we don't want to delete the admin queue
|
||||
push ecx
|
||||
stdcall delete_io_completion_queue, esi, ecx
|
||||
pop ecx
|
||||
push ecx
|
||||
stdcall delete_io_submission_queue, esi, ecx
|
||||
pop ecx
|
||||
stdcall delete_io_submission_queue, esi, ebx
|
||||
stdcall delete_io_completion_queue, esi, ebx
|
||||
|
||||
@@:
|
||||
invoke KernelFree, dword [edi + NVM_QUEUE_ENTRY.cq_ptr]
|
||||
invoke KernelFree, dword [edi + NVM_QUEUE_ENTRY.sq_ptr]
|
||||
pop ecx
|
||||
|
||||
; Free the commands and their respective mutexes
|
||||
push edi ecx
|
||||
xor ecx, ecx
|
||||
mov edi, dword [edi + NVM_QUEUE_ENTRY.cmd_ptr]
|
||||
sub edi, sizeof.NVMQCMD
|
||||
|
||||
.get_cmd:
|
||||
add edi, sizeof.NVMQCMD
|
||||
push ecx
|
||||
invoke KernelFree, dword [edi + NVMQCMD.mutex_ptr]
|
||||
pop ecx
|
||||
inc ecx
|
||||
cmp ecx, SQ_ENTRIES
|
||||
jne .get_cmd
|
||||
pop ecx edi
|
||||
|
||||
inc ecx
|
||||
cmp ecx, LAST_QUEUE_ID
|
||||
jne .get_queue
|
||||
|
||||
invoke KernelFree, dword [esi + pcidev.queue_entries]
|
||||
inc ebx
|
||||
cmp ebx, LAST_QUEUE_ID
|
||||
jbe .get_queue
|
||||
pop ebx
|
||||
cmp ebx, dword [pcidevs_len]
|
||||
jne .get_pcidev
|
||||
|
||||
; Shutdown the controller
|
||||
mov edi, dword [esi + pcidev.io_addr]
|
||||
@ -1326,8 +1306,8 @@ proc nvme_cleanup
|
||||
test byte [edi + NVME_MMIO.CSTS], CSTS_SHST_SHUTDOWN_COMPLETE
|
||||
jnz @b
|
||||
|
||||
.free_pcidevs:
|
||||
invoke KernelFree, dword [p_nvme_devices]
|
||||
.ret:
|
||||
pop edi esi ebx
|
||||
ret
|
||||
|
||||
endp
|
||||
|
Loading…
Reference in New Issue
Block a user