Skip to content

Commit 6e422cf

Browse files
committed
nvme: mi: dev: Implement Admin / Identify / Identify Namespace for Allocated Namespace ID
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
1 parent 123155f commit 6e422cf

3 files changed

Lines changed: 343 additions & 17 deletions

File tree

src/nvme.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ enum AdminIoCqeGenericCommandStatus {
108108
SuccessfulCompletion = 0x00,
109109
InvalidFieldInCommand = 0x02,
110110
InternalError = 0x06,
111+
InvalidNamespaceOrFormat = 0x0b,
111112
}
112113
unsafe impl Discriminant<u8> for AdminIoCqeGenericCommandStatus {}
113114

@@ -384,6 +385,7 @@ enum AdminIdentifyCnsRequestType {
384385
IoActiveNamespaceIdList = 0x07,
385386
IdentifyNamespace = 0x08,
386387
AllocatedNamespaceIdList = 0x10,
388+
IdentifyNamespaceForAllocatedNamespaceId = 0x11,
387389
NvmSubsystemControllerList = 0x13,
388390
SecondaryControllerList = 0x15,
389391
}
@@ -413,6 +415,26 @@ pub struct AdminIdentifyNvmIdentifyNamespaceResponse {
413415
}
414416
impl Encode<4096> for AdminIdentifyNvmIdentifyNamespaceResponse {}
415417

418+
impl From<&crate::Namespace> for AdminIdentifyNvmIdentifyNamespaceResponse {
419+
fn from(value: &crate::Namespace) -> Self {
420+
Self {
421+
nsze: value.size,
422+
ncap: value.capacity,
423+
nuse: value.used,
424+
nsfeat: ((value.size == value.capacity) as u8),
425+
nlbaf: 0,
426+
flbas: 0,
427+
mc: 0,
428+
dpc: 0,
429+
dps: 0,
430+
nvmcap: 2_u128.pow(value.block_order as u32) * value.size as u128,
431+
lbaf0: 0,
432+
lbaf0_lbads: value.block_order,
433+
lbaf0_rp: 0,
434+
}
435+
}
436+
}
437+
416438
// Base v2.1, 5.1.13.1, Figure 311
417439
#[derive(Clone, Copy, Debug, DekuRead, DekuWrite)]
418440
#[deku(id_type = "u8", endian = "endian", ctx = "endian: Endian")]

src/nvme/mi/dev.rs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,23 +1261,7 @@ impl RequestHandler for AdminIdentifyRequest {
12611261
Ok(AdminIdentifyNvmIdentifyNamespaceResponse::default())
12621262
}
12631263
// 4.1.5.1 NVM Command Set Spec, v1.0c
1264-
NamespaceIdDisposition::Active(ns) => {
1265-
Ok(AdminIdentifyNvmIdentifyNamespaceResponse {
1266-
nsze: ns.size,
1267-
ncap: ns.capacity,
1268-
nuse: ns.used,
1269-
nsfeat: ((ns.size == ns.capacity) as u8),
1270-
nlbaf: 0,
1271-
flbas: 0,
1272-
mc: 0,
1273-
dpc: 0,
1274-
dps: 0,
1275-
nvmcap: 2_u128.pow(ns.block_order as u32) * ns.size as u128,
1276-
lbaf0: 0,
1277-
lbaf0_lbads: ns.block_order,
1278-
lbaf0_rp: 0,
1279-
})
1280-
}
1264+
NamespaceIdDisposition::Active(ns) => Ok(ns.into()),
12811265
}?
12821266
.encode()?;
12831267

@@ -1480,6 +1464,37 @@ impl RequestHandler for AdminIdentifyRequest {
14801464
)
14811465
.await
14821466
}
1467+
AdminIdentifyCnsRequestType::IdentifyNamespaceForAllocatedNamespaceId => {
1468+
// Base v2.1, 5.1.13.2.10
1469+
match match NamespaceId(self.nsid).disposition(subsys) {
1470+
NamespaceIdDisposition::Invalid | NamespaceIdDisposition::Broadcast => {
1471+
Err(AdminIoCqeGenericCommandStatus::InvalidNamespaceOrFormat)
1472+
}
1473+
NamespaceIdDisposition::Unallocated => {
1474+
AdminIdentifyNvmIdentifyNamespaceResponse::default()
1475+
.encode()
1476+
.map_err(AdminIoCqeGenericCommandStatus::from)
1477+
}
1478+
NamespaceIdDisposition::Inactive(ns) | NamespaceIdDisposition::Active(ns) => {
1479+
let ainvminr: AdminIdentifyNvmIdentifyNamespaceResponse = ns.into();
1480+
ainvminr
1481+
.encode()
1482+
.map_err(AdminIoCqeGenericCommandStatus::from)
1483+
}
1484+
} {
1485+
Ok(response) => {
1486+
admin_send_response_body(
1487+
resp,
1488+
admin_constrain_body(self.dofst, self.dlen, &response.0)?,
1489+
)
1490+
.await
1491+
}
1492+
Err(err) => {
1493+
admin_send_status(resp, AdminIoCqeStatusType::GenericCommandStatus(err))
1494+
.await
1495+
}
1496+
}
1497+
}
14831498
AdminIdentifyCnsRequestType::NvmSubsystemControllerList => {
14841499
assert!(
14851500
subsys.ctlrs.len() <= 2047,

0 commit comments

Comments
 (0)