Skip to content

Commit 2dd5c48

Browse files
committed
nvme: mi: dev: Use Admin status responses for Admin / Identify
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
1 parent e42413b commit 2dd5c48

2 files changed

Lines changed: 115 additions & 58 deletions

File tree

src/nvme/mi/dev.rs

Lines changed: 108 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,34 +1242,47 @@ impl RequestHandler for AdminIdentifyRequest {
12421242

12431243
match &self.req {
12441244
AdminIdentifyCnsRequestType::NvmIdentifyNamespace => {
1245-
let ainvminr = match NamespaceId(self.nsid).disposition(subsys) {
1245+
match match NamespaceId(self.nsid).disposition(subsys) {
12461246
NamespaceIdDisposition::Invalid => {
12471247
debug!("Invalid NSID: {}", self.nsid);
1248-
Err(ResponseStatus::InvalidParameter)
1248+
Err(AdminIoCqeGenericCommandStatus::InvalidNamespaceOrFormat)
12491249
}
12501250
NamespaceIdDisposition::Broadcast => {
1251-
Ok(AdminIdentifyNvmIdentifyNamespaceResponse {
1251+
AdminIdentifyNvmIdentifyNamespaceResponse {
12521252
lbaf0_lbads: 9, // TODO: Tie to controller model
12531253
..Default::default()
1254-
})
1254+
}
1255+
.encode()
1256+
.map_err(AdminIoCqeGenericCommandStatus::from)
12551257
}
12561258
NamespaceIdDisposition::Unallocated => {
12571259
debug!("Unallocated NSID: {}", self.nsid);
1258-
Err(ResponseStatus::InvalidParameter)
1260+
Err(AdminIoCqeGenericCommandStatus::InvalidNamespaceOrFormat)
12591261
}
12601262
NamespaceIdDisposition::Inactive(_) => {
1261-
Ok(AdminIdentifyNvmIdentifyNamespaceResponse::default())
1263+
AdminIdentifyNvmIdentifyNamespaceResponse::default()
1264+
.encode()
1265+
.map_err(AdminIoCqeGenericCommandStatus::from)
12621266
}
12631267
// 4.1.5.1 NVM Command Set Spec, v1.0c
1264-
NamespaceIdDisposition::Active(ns) => Ok(ns.into()),
1265-
}?
1266-
.encode()?;
1267-
1268-
admin_send_response_body(
1269-
resp,
1270-
admin_constrain_body(self.dofst, self.dlen, &ainvminr.0)?,
1271-
)
1272-
.await
1268+
NamespaceIdDisposition::Active(ns) => {
1269+
Into::<AdminIdentifyNvmIdentifyNamespaceResponse>::into(ns)
1270+
.encode()
1271+
.map_err(AdminIoCqeGenericCommandStatus::from)
1272+
}
1273+
} {
1274+
Ok(response) => {
1275+
admin_send_response_body(
1276+
resp,
1277+
admin_constrain_body(self.dofst, self.dlen, &response.0)?,
1278+
)
1279+
.await
1280+
}
1281+
Err(err) => {
1282+
admin_send_status(resp, AdminIoCqeStatusType::GenericCommandStatus(err))
1283+
.await
1284+
}
1285+
}
12731286
}
12741287
AdminIdentifyCnsRequestType::IdentifyController => {
12751288
let Some(ctlr) = subsys.ctlrs.get(ctx.ctlid as usize) else {
@@ -1343,13 +1356,22 @@ impl RequestHandler for AdminIdentifyRequest {
13431356
apsta: 0,
13441357
sanicap: subsys.sanicap.into(),
13451358
}
1346-
.encode()?;
1359+
.encode()
1360+
.map_err(AdminIoCqeGenericCommandStatus::from);
13471361

1348-
admin_send_response_body(
1349-
resp,
1350-
admin_constrain_body(self.dofst, self.dlen, &aicr.0)?,
1351-
)
1352-
.await
1362+
match aicr {
1363+
Ok(response) => {
1364+
admin_send_response_body(
1365+
resp,
1366+
admin_constrain_body(self.dofst, self.dlen, &response.0)?,
1367+
)
1368+
.await
1369+
}
1370+
Err(err) => {
1371+
admin_send_status(resp, AdminIoCqeStatusType::GenericCommandStatus(err))
1372+
.await
1373+
}
1374+
}
13531375
}
13541376
AdminIdentifyCnsRequestType::ActiveNamespaceIDList => {
13551377
// 5.1.13.2.2, Base v2.1
@@ -1374,17 +1396,27 @@ impl RequestHandler for AdminIdentifyRequest {
13741396
return Err(ResponseStatus::InternalError);
13751397
};
13761398
}
1377-
let aianidlr = aianidlr.encode()?;
1399+
let aianidlr = aianidlr
1400+
.encode()
1401+
.map_err(AdminIoCqeGenericCommandStatus::from);
13781402

1379-
admin_send_response_body(
1380-
resp,
1381-
admin_constrain_body(self.dofst, self.dlen, &aianidlr.0)?,
1382-
)
1383-
.await
1403+
match aianidlr {
1404+
Ok(response) => {
1405+
admin_send_response_body(
1406+
resp,
1407+
admin_constrain_body(self.dofst, self.dlen, &response.0)?,
1408+
)
1409+
.await
1410+
}
1411+
Err(err) => {
1412+
admin_send_status(resp, AdminIoCqeStatusType::GenericCommandStatus(err))
1413+
.await
1414+
}
1415+
}
13841416
}
13851417
AdminIdentifyCnsRequestType::NamespaceIdentificationDescriptorList => {
13861418
// 5.1.13.2.3, Base v2.1
1387-
let ainsidlr = match NamespaceId(self.nsid).disposition(subsys) {
1419+
match match NamespaceId(self.nsid).disposition(subsys) {
13881420
NamespaceIdDisposition::Invalid => {
13891421
if self.nsid == u32::MAX - 1 {
13901422
debug!(
@@ -1393,18 +1425,18 @@ impl RequestHandler for AdminIdentifyRequest {
13931425
} else {
13941426
debug!("Invalid NSID: {}", self.nsid);
13951427
}
1396-
Err(ResponseStatus::InvalidParameter)
1428+
Err(AdminIoCqeGenericCommandStatus::InvalidNamespaceOrFormat)
13971429
}
13981430
NamespaceIdDisposition::Broadcast => {
13991431
debug!("Invalid NSID: {}", self.nsid);
1400-
Err(ResponseStatus::InvalidParameter)
1432+
Err(AdminIoCqeGenericCommandStatus::InvalidNamespaceOrFormat)
14011433
}
14021434
NamespaceIdDisposition::Unallocated => {
14031435
debug!("Unallocated NSID: {}", self.nsid);
1404-
Err(ResponseStatus::InvalidParameter)
1436+
Err(AdminIoCqeGenericCommandStatus::InvalidNamespaceOrFormat)
14051437
}
14061438
NamespaceIdDisposition::Inactive(ns) | NamespaceIdDisposition::Active(ns) => {
1407-
Ok(AdminIdentifyNamespaceIdentificationDescriptorListResponse {
1439+
AdminIdentifyNamespaceIdentificationDescriptorListResponse {
14081440
nids: {
14091441
let mut vec = WireVec::new();
14101442
for nid in &ns.nids {
@@ -1418,16 +1450,23 @@ impl RequestHandler for AdminIdentifyRequest {
14181450
}
14191451
vec
14201452
},
1421-
})
1453+
}
1454+
.encode()
1455+
.map_err(AdminIoCqeGenericCommandStatus::from)
14221456
}
1423-
}?
1424-
.encode()?;
1425-
1426-
admin_send_response_body(
1427-
resp,
1428-
admin_constrain_body(self.dofst, self.dlen, &ainsidlr.0)?,
1429-
)
1430-
.await
1457+
} {
1458+
Ok(response) => {
1459+
admin_send_response_body(
1460+
resp,
1461+
admin_constrain_body(self.dofst, self.dlen, &response.0)?,
1462+
)
1463+
.await
1464+
}
1465+
Err(err) => {
1466+
admin_send_status(resp, AdminIoCqeStatusType::GenericCommandStatus(err))
1467+
.await
1468+
}
1469+
}
14311470
}
14321471
AdminIdentifyCnsRequestType::AllocatedNamespaceIdList => {
14331472
// 5.1.13.2.9, Base v2.1
@@ -1456,13 +1495,22 @@ impl RequestHandler for AdminIdentifyRequest {
14561495
vec
14571496
},
14581497
}
1459-
.encode()?;
1498+
.encode()
1499+
.map_err(AdminIoCqeGenericCommandStatus::from);
14601500

1461-
admin_send_response_body(
1462-
resp,
1463-
admin_constrain_body(self.dofst, self.dlen, &aiansidl.0)?,
1464-
)
1465-
.await
1501+
match aiansidl {
1502+
Ok(response) => {
1503+
admin_send_response_body(
1504+
resp,
1505+
admin_constrain_body(self.dofst, self.dlen, &response.0)?,
1506+
)
1507+
.await
1508+
}
1509+
Err(err) => {
1510+
admin_send_status(resp, AdminIoCqeStatusType::GenericCommandStatus(err))
1511+
.await
1512+
}
1513+
}
14661514
}
14671515
AdminIdentifyCnsRequestType::IdentifyNamespaceForAllocatedNamespaceId => {
14681516
// Base v2.1, 5.1.13.2.10
@@ -1553,10 +1601,19 @@ impl RequestHandler for AdminIdentifyRequest {
15531601
};
15541602
}
15551603
cl.update()?;
1556-
let cl = cl.encode()?;
1557-
1558-
admin_send_response_body(resp, admin_constrain_body(self.dofst, self.dlen, &cl.0)?)
1559-
.await
1604+
match cl.encode().map_err(AdminIoCqeGenericCommandStatus::from) {
1605+
Ok(response) => {
1606+
admin_send_response_body(
1607+
resp,
1608+
admin_constrain_body(self.dofst, self.dlen, &response.0)?,
1609+
)
1610+
.await
1611+
}
1612+
Err(status) => {
1613+
admin_send_status(resp, AdminIoCqeStatusType::GenericCommandStatus(status))
1614+
.await
1615+
}
1616+
}
15601617
}
15611618
AdminIdentifyCnsRequestType::SecondaryControllerList => {
15621619
let Some(ctlr) = subsys.ctlrs.get(ctx.ctlid as usize) else {

tests/admin.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ mod identify {
633633
0x12, 0x14, 0x1c, 0x57
634634
];
635635

636-
let resp = ExpectedRespChannel::new(&RESP_INVALID_PARAMETER);
636+
let resp = ExpectedRespChannel::new(&RESP_ADMIN_STATUS_INVALID_NAMESPACE);
637637
smol::block_on(async {
638638
mep.handle_async(&mut subsys, &REQ, MsgIC(true), resp, async |_| Ok(()))
639639
.await
@@ -724,7 +724,7 @@ mod identify {
724724
0x49, 0xb0, 0xa7, 0x22
725725
];
726726

727-
let resp = ExpectedRespChannel::new(&RESP_INVALID_PARAMETER);
727+
let resp = ExpectedRespChannel::new(&RESP_ADMIN_STATUS_INVALID_NAMESPACE);
728728
smol::block_on(async {
729729
mep.handle_async(&mut subsys, &REQ, MsgIC(true), resp, async |_| Ok(()))
730730
.await
@@ -1078,7 +1078,7 @@ mod identify {
10781078
0xe4, 0x7b, 0x6f, 0x4c
10791079
];
10801080

1081-
let resp = ExpectedRespChannel::new(&RESP_INVALID_PARAMETER);
1081+
let resp = ExpectedRespChannel::new(&RESP_ADMIN_STATUS_INVALID_NAMESPACE);
10821082
smol::block_on(async {
10831083
mep.handle_async(&mut subsys, &REQ, MsgIC(true), resp, async |_| Ok(()))
10841084
.await
@@ -1123,7 +1123,7 @@ mod identify {
11231123
0xbf, 0xdf, 0xd4, 0x39
11241124
];
11251125

1126-
let resp = ExpectedRespChannel::new(&RESP_INVALID_PARAMETER);
1126+
let resp = ExpectedRespChannel::new(&RESP_ADMIN_STATUS_INVALID_NAMESPACE);
11271127
smol::block_on(async {
11281128
mep.handle_async(&mut subsys, &REQ, MsgIC(true), resp, async |_| Ok(()))
11291129
.await
@@ -1168,7 +1168,7 @@ mod identify {
11681168
0x71, 0x25, 0x20, 0x9c
11691169
];
11701170

1171-
let resp = ExpectedRespChannel::new(&RESP_INVALID_PARAMETER);
1171+
let resp = ExpectedRespChannel::new(&RESP_ADMIN_STATUS_INVALID_NAMESPACE);
11721172
smol::block_on(async {
11731173
mep.handle_async(&mut subsys, &REQ, MsgIC(true), resp, async |_| Ok(()))
11741174
.await
@@ -1213,7 +1213,7 @@ mod identify {
12131213
0x9c, 0xc9, 0xec, 0x02
12141214
];
12151215

1216-
let resp = ExpectedRespChannel::new(&RESP_INVALID_PARAMETER);
1216+
let resp = ExpectedRespChannel::new(&RESP_ADMIN_STATUS_INVALID_NAMESPACE);
12171217
smol::block_on(async {
12181218
mep.handle_async(&mut subsys, &REQ, MsgIC(true), resp, async |_| Ok(()))
12191219
.await
@@ -1258,7 +1258,7 @@ mod identify {
12581258
0xc7, 0x6d, 0x57, 0x77
12591259
];
12601260

1261-
let resp = ExpectedRespChannel::new(&RESP_INVALID_PARAMETER);
1261+
let resp = ExpectedRespChannel::new(&RESP_ADMIN_STATUS_INVALID_NAMESPACE);
12621262
smol::block_on(async {
12631263
mep.handle_async(&mut subsys, &REQ, MsgIC(true), resp, async |_| Ok(()))
12641264
.await

0 commit comments

Comments
 (0)