@@ -1240,9 +1240,9 @@ impl RequestHandler for AdminIdentifyRequest {
12401240 return Err ( ResponseStatus :: InvalidCommandSize ) ;
12411241 }
12421242
1243- match & self . req {
1243+ let res = match & self . req {
12441244 AdminIdentifyCnsRequestType :: NvmIdentifyNamespace => {
1245- match match NamespaceId ( self . nsid ) . disposition ( subsys) {
1245+ match NamespaceId ( self . nsid ) . disposition ( subsys) {
12461246 NamespaceIdDisposition :: Invalid => {
12471247 debug ! ( "Invalid NSID: {}" , self . nsid) ;
12481248 Err ( AdminIoCqeGenericCommandStatus :: InvalidNamespaceOrFormat )
@@ -1270,107 +1270,81 @@ impl RequestHandler for AdminIdentifyRequest {
12701270 . encode ( )
12711271 . map_err ( AdminIoCqeGenericCommandStatus :: from)
12721272 }
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- }
12851273 }
12861274 }
12871275 AdminIdentifyCnsRequestType :: IdentifyController => {
1288- let Some ( ctlr) = subsys. ctlrs . get ( ctx. ctlid as usize ) else {
1289- debug ! ( "No such CTLID: {}" , ctx. ctlid) ;
1290- return Err ( ResponseStatus :: InvalidParameter ) ;
1291- } ;
1292-
1293- let aicr = AdminIdentifyControllerResponse {
1294- vid : subsys. info . pci_vid ,
1295- ssvid : subsys. info . pci_svid ,
1296- sn : WireString :: from ( subsys. sn ) ?,
1297- mn : WireString :: from ( subsys. mn ) ?,
1298- fr : WireString :: from ( subsys. fr ) ?,
1299- rab : 0 ,
1300- ieee : {
1301- // 4.5.3, Base v2.1
1302- let mut fixup = subsys. info . ieee_oui ;
1303- fixup. reverse ( ) ;
1304- fixup
1305- } ,
1306- cmic : ( ( subsys. ctlrs . len ( ) > 1 ) as u8 ) << 1 // MCTRS
1276+ if let Some ( ctlr) = subsys. ctlrs . get ( ctx. ctlid as usize ) {
1277+ AdminIdentifyControllerResponse {
1278+ vid : subsys. info . pci_vid ,
1279+ ssvid : subsys. info . pci_svid ,
1280+ sn : WireString :: from ( subsys. sn ) ?,
1281+ mn : WireString :: from ( subsys. mn ) ?,
1282+ fr : WireString :: from ( subsys. fr ) ?,
1283+ rab : 0 ,
1284+ ieee : {
1285+ // 4.5.3, Base v2.1
1286+ let mut fixup = subsys. info . ieee_oui ;
1287+ fixup. reverse ( ) ;
1288+ fixup
1289+ } ,
1290+ cmic : ( ( subsys. ctlrs . len ( ) > 1 ) as u8 ) << 1 // MCTRS
13071291 | ( ( subsys. ports . len ( ) > 1 ) as u8 ) , // MPORTS
1308- mdts : 0 ,
1309- cntlid : ctlr. id . 0 ,
1310- ver : 0 ,
1311- rtd3r : 0 ,
1312- rtd3e : 0 ,
1313- oaes : 0 ,
1314- // TODO: Tie to data model
1315- ctratt : ( ( false as u32 ) << 14 ) // DNVMS
1292+ mdts : 0 ,
1293+ cntlid : ctlr. id . 0 ,
1294+ ver : 0 ,
1295+ rtd3r : 0 ,
1296+ rtd3e : 0 ,
1297+ oaes : 0 ,
1298+ // TODO: Tie to data model
1299+ ctratt : ( ( false as u32 ) << 14 ) // DNVMS
13161300 | ( ( false as u32 ) << 13 ) // DEG
13171301 | ( ( false as u32 ) << 4 ) // EGS
13181302 | ( ( false as u32 ) << 2 ) , // NSETS
1319- cntrltype : ctlr. cntrltype . into ( ) ,
1320- // TODO: Tie to data model
1321- nvmsr : ( ( false as u8 ) << 1 ) // NVMEE
1303+ cntrltype : ctlr. cntrltype . into ( ) ,
1304+ // TODO: Tie to data model
1305+ nvmsr : ( ( false as u8 ) << 1 ) // NVMEE
13221306 | ( true as u8 ) , // NVMESD
1323- vwci : 0 ,
1324- mec : ( ( subsys. ports . iter ( ) . any ( |p| matches ! ( p. typ, crate :: PortType :: Pcie ( _) ) ) ) as u8 ) << 1 // PCIEME
1307+ vwci : 0 ,
1308+ mec : ( ( subsys. ports . iter ( ) . any ( |p| matches ! ( p. typ, crate :: PortType :: Pcie ( _) ) ) ) as u8 ) << 1 // PCIEME
13251309 | ( subsys. ports . iter ( ) . any ( |p| matches ! ( p. typ, crate :: PortType :: TwoWire ( _) ) ) ) as u8 , // TWPME
1326- ocas : 0 ,
1327- acl : 0 ,
1328- aerl : 0 ,
1329- frmw : 0 ,
1330- lpa : ctlr. lpa . into ( ) ,
1331- elpe : 0 ,
1332- npss : 0 ,
1333- avscc : 0 ,
1334- wctemp : 0x157 ,
1335- cctemp : 0x157 ,
1336- fwug : 0 ,
1337- kas : 0 ,
1338- cqt : 0 ,
1339- sqes : 0 ,
1340- cqes : 0 ,
1341- maxcmd : 0 ,
1342- nn : NamespaceId :: max ( subsys) ,
1343- oncs : 0 ,
1344- fuses : 0 ,
1345- fna : ctlr. fna . into ( ) ,
1346- vwc : 0 ,
1347- awun : 0 ,
1348- awupf : 0 ,
1349- icsvscc : 0 ,
1350- nwpc : 0 ,
1351- mnan : 0 ,
1352- subnqn : WireString :: new ( ) ,
1353- fcatt : 0 ,
1354- msdbd : 0 ,
1355- ofcs : 0 ,
1356- apsta : 0 ,
1357- sanicap : subsys. sanicap . into ( ) ,
1358- }
1359- . encode ( )
1360- . map_err ( AdminIoCqeGenericCommandStatus :: from) ;
1361-
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
1310+ ocas : 0 ,
1311+ acl : 0 ,
1312+ aerl : 0 ,
1313+ frmw : 0 ,
1314+ lpa : ctlr. lpa . into ( ) ,
1315+ elpe : 0 ,
1316+ npss : 0 ,
1317+ avscc : 0 ,
1318+ wctemp : 0x157 ,
1319+ cctemp : 0x157 ,
1320+ fwug : 0 ,
1321+ kas : 0 ,
1322+ cqt : 0 ,
1323+ sqes : 0 ,
1324+ cqes : 0 ,
1325+ maxcmd : 0 ,
1326+ nn : NamespaceId :: max ( subsys) ,
1327+ oncs : 0 ,
1328+ fuses : 0 ,
1329+ fna : ctlr. fna . into ( ) ,
1330+ vwc : 0 ,
1331+ awun : 0 ,
1332+ awupf : 0 ,
1333+ icsvscc : 0 ,
1334+ nwpc : 0 ,
1335+ mnan : 0 ,
1336+ subnqn : WireString :: new ( ) ,
1337+ fcatt : 0 ,
1338+ msdbd : 0 ,
1339+ ofcs : 0 ,
1340+ apsta : 0 ,
1341+ sanicap : subsys. sanicap . into ( ) ,
13731342 }
1343+ . encode ( )
1344+ . map_err ( AdminIoCqeGenericCommandStatus :: from)
1345+ } else {
1346+ debug ! ( "No such CTLID: {}" , ctx. ctlid) ;
1347+ Err ( AdminIoCqeGenericCommandStatus :: InvalidFieldInCommand )
13741348 }
13751349 }
13761350 AdminIdentifyCnsRequestType :: ActiveNamespaceIDList => {
@@ -1396,27 +1370,13 @@ impl RequestHandler for AdminIdentifyRequest {
13961370 return Err ( ResponseStatus :: InternalError ) ;
13971371 } ;
13981372 }
1399- let aianidlr = aianidlr
1373+ aianidlr
14001374 . encode ( )
1401- . map_err ( AdminIoCqeGenericCommandStatus :: from) ;
1402-
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- }
1375+ . map_err ( AdminIoCqeGenericCommandStatus :: from)
14161376 }
14171377 AdminIdentifyCnsRequestType :: NamespaceIdentificationDescriptorList => {
14181378 // 5.1.13.2.3, Base v2.1
1419- match match NamespaceId ( self . nsid ) . disposition ( subsys) {
1379+ match NamespaceId ( self . nsid ) . disposition ( subsys) {
14201380 NamespaceIdDisposition :: Invalid => {
14211381 if self . nsid == u32:: MAX - 1 {
14221382 debug ! (
@@ -1454,18 +1414,6 @@ impl RequestHandler for AdminIdentifyRequest {
14541414 . encode ( )
14551415 . map_err ( AdminIoCqeGenericCommandStatus :: from)
14561416 }
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- }
14691417 }
14701418 }
14711419 AdminIdentifyCnsRequestType :: AllocatedNamespaceIdList => {
@@ -1476,7 +1424,7 @@ impl RequestHandler for AdminIdentifyRequest {
14761424 }
14771425
14781426 assert ! ( NamespaceId :: max( subsys) < ( 4096 / core:: mem:: size_of:: <u32 >( ) ) as u32 ) ;
1479- let aiansidl = AdminIdentifyAllocatedNamespaceIdListResponse {
1427+ AdminIdentifyAllocatedNamespaceIdListResponse {
14801428 nsid : {
14811429 let mut allocated: heapless:: Vec < u32 , MAX_NAMESPACES > = subsys
14821430 . nss
@@ -1496,25 +1444,11 @@ impl RequestHandler for AdminIdentifyRequest {
14961444 } ,
14971445 }
14981446 . encode ( )
1499- . map_err ( AdminIoCqeGenericCommandStatus :: from) ;
1500-
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- }
1447+ . map_err ( AdminIoCqeGenericCommandStatus :: from)
15141448 }
15151449 AdminIdentifyCnsRequestType :: IdentifyNamespaceForAllocatedNamespaceId => {
15161450 // Base v2.1, 5.1.13.2.10
1517- match match NamespaceId ( self . nsid ) . disposition ( subsys) {
1451+ match NamespaceId ( self . nsid ) . disposition ( subsys) {
15181452 NamespaceIdDisposition :: Invalid | NamespaceIdDisposition :: Broadcast => {
15191453 Err ( AdminIoCqeGenericCommandStatus :: InvalidNamespaceOrFormat )
15201454 }
@@ -1529,22 +1463,10 @@ impl RequestHandler for AdminIdentifyRequest {
15291463 . encode ( )
15301464 . map_err ( AdminIoCqeGenericCommandStatus :: from)
15311465 }
1532- } {
1533- Ok ( response) => {
1534- admin_send_response_body (
1535- resp,
1536- admin_constrain_body ( self . dofst , self . dlen , & response. 0 ) ?,
1537- )
1538- . await
1539- }
1540- Err ( err) => {
1541- admin_send_status ( resp, AdminIoCqeStatusType :: GenericCommandStatus ( err) )
1542- . await
1543- }
15441466 }
15451467 }
15461468 AdminIdentifyCnsRequestType :: NamespaceAttachedControllerList => {
1547- match match NamespaceId ( self . nsid ) . disposition ( subsys) {
1469+ match NamespaceId ( self . nsid ) . disposition ( subsys) {
15481470 NamespaceIdDisposition :: Invalid => ControllerListResponse :: new ( )
15491471 . encode ( )
15501472 . map_err ( AdminIoCqeGenericCommandStatus :: from) ,
@@ -1573,18 +1495,6 @@ impl RequestHandler for AdminIdentifyRequest {
15731495 clr. update ( ) ?;
15741496 clr. encode ( ) . map_err ( AdminIoCqeGenericCommandStatus :: from)
15751497 }
1576- } {
1577- Ok ( response) => {
1578- admin_send_response_body (
1579- resp,
1580- admin_constrain_body ( self . dofst , self . dlen , & response. 0 ) ?,
1581- )
1582- . await
1583- }
1584- Err ( status) => {
1585- admin_send_status ( resp, AdminIoCqeStatusType :: GenericCommandStatus ( status) )
1586- . await
1587- }
15881498 }
15891499 }
15901500 AdminIdentifyCnsRequestType :: NvmSubsystemControllerList => {
@@ -1601,19 +1511,7 @@ impl RequestHandler for AdminIdentifyRequest {
16011511 } ;
16021512 }
16031513 cl. update ( ) ?;
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- }
1514+ cl. encode ( ) . map_err ( AdminIoCqeGenericCommandStatus :: from)
16171515 }
16181516 AdminIdentifyCnsRequestType :: SecondaryControllerList => {
16191517 let Some ( ctlr) = subsys. ctlrs . get ( ctx. ctlid as usize ) else {
@@ -1625,15 +1523,24 @@ impl RequestHandler for AdminIdentifyRequest {
16251523 todo ! ( "Support listing secondary controllers" ) ;
16261524 }
16271525
1526+ Ok ( ( [ 0u8 ; 4096 ] , 4096usize ) )
1527+ }
1528+ _ => {
1529+ debug ! ( "Unimplemented CNS: {self:?}" ) ;
1530+ return Err ( ResponseStatus :: InternalError ) ;
1531+ }
1532+ } ;
1533+
1534+ match res {
1535+ Ok ( response) => {
16281536 admin_send_response_body (
16291537 resp,
1630- admin_constrain_body ( self . dofst , self . dlen , & [ 0u8 ; 4096 ] ) ?,
1538+ admin_constrain_body ( self . dofst , self . dlen , & response . 0 ) ?,
16311539 )
16321540 . await
16331541 }
1634- _ => {
1635- debug ! ( "Unimplemented CNS: {self:?}" ) ;
1636- Err ( ResponseStatus :: InternalError )
1542+ Err ( err) => {
1543+ admin_send_status ( resp, AdminIoCqeStatusType :: GenericCommandStatus ( err) ) . await
16371544 }
16381545 }
16391546 }
0 commit comments