Skip to content

Commit 1232b85

Browse files
committed
nvme: admin fixes for controllers with multiple namespaces
1 parent 5d966d2 commit 1232b85

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

devices/sdev/nvme/src/admin.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ int nvmeIdentify(NVMEController *drive) {
6060
luxLogf(KPRINT_LEVEL_DEBUG, "- model: %s\n", drive->model);
6161

6262
int ctrlType = drive->id->controllerType-1;
63-
if(ctrlType >= 0 && ctrlType <= 2) {
63+
if(!drive->id->controllerType) {
64+
luxLogf(KPRINT_LEVEL_WARNING, "- controller type: %d (reserved, assuming legacy I/O controller)\n", drive->id->controllerType);
65+
} else if(ctrlType >= 0 && ctrlType <= 2) {
6466
luxLogf(KPRINT_LEVEL_DEBUG, "- controller type: %s\n", controllerType[ctrlType]);
6567
} else {
6668
luxLogf(KPRINT_LEVEL_WARNING, "- controller type: %d (unimplemented), aborting...\n", drive->id->controllerType);
@@ -186,14 +188,14 @@ int nvmeIdentify(NVMEController *drive) {
186188
cmd.dword11 = 0x00; // CSI 0x00 = NVM I/O command set
187189
nvmeSubmit(drive, 0, &cmd);
188190
if(!nvmePoll(drive, 0, i + 0xBEEF, 20)) {
189-
luxLogf(KPRINT_LEVEL_WARNING, "- timeout while identifying NVM namespace %d (0x%08X), aborting...\n", i, drive->ns[i]);
190-
return -1;
191+
luxLogf(KPRINT_LEVEL_WARNING, "- timeout while identifying NVM namespace %d (0x%08X), skipping...\n", i, drive->ns[i]);
192+
continue;
191193
}
192194

193195
NVMIONSIdentification *nvmNSID = (NVMIONSIdentification *) drive->id;
194196
if(!nvmNSID->lbaFormatCount) {
195-
luxLogf(KPRINT_LEVEL_WARNING, "- drive does not report any LBA formats, aborting...\n");
196-
return -1;
197+
//luxLogf(KPRINT_LEVEL_WARNING, "- NS %d: drive doesn't report any LBA formats, skipping...\n", i+1);
198+
continue;
197199
}
198200

199201
drive->nsSectorSizes[i] = 1 << nvmNSID->lbaFormat[0].sectorSize;
@@ -345,6 +347,8 @@ int nvmeIdentify(NVMEController *drive) {
345347
}
346348

347349
for(int i = 0; i < drive->nsCount; i++) {
350+
if(!drive->nsSizes[i] || !drive->nsSectorSizes[i]) continue;
351+
348352
memset(regcmd, 0, sizeof(SDevRegisterCommand));
349353
regcmd->header.command = COMMAND_SDEV_REGISTER;
350354
regcmd->header.length = sizeof(SDevRegisterCommand);
@@ -369,9 +373,10 @@ int nvmeIdentify(NVMEController *drive) {
369373
return -1;
370374
}
371375

376+
uint8_t statype = (res->status >> 8) & 7;
372377
uint8_t status = (res->status >> 1) & 0xFF;
373378
if(status) {
374-
luxLogf(KPRINT_LEVEL_WARNING, "- I/O error while reading boot sector, error code 0x%02X, aborting...\n");
379+
luxLogf(KPRINT_LEVEL_WARNING, "- I/O error while reading boot sector, status type 0x%02X code 0x%02X, aborting...\n", statype, status);
375380
free(regcmd);
376381
return -1;
377382
}

0 commit comments

Comments
 (0)