@@ -12,9 +12,10 @@ use crate::{
1212 CommandEffect , CommandEffectError , Controller , ControllerError , ControllerType , Discriminant ,
1313 MAX_CONTROLLERS , MAX_NAMESPACES , NamespaceId , SubsystemError ,
1414 nvme:: {
15- AdminGetLogPageLidRequestType , AdminGetLogPageSupportedLogPagesResponse ,
16- AdminIdentifyActiveNamespaceIdListResponse , AdminIdentifyAllocatedNamespaceIdListResponse ,
17- AdminIdentifyCnsRequestType , AdminIdentifyControllerResponse ,
15+ AdminFormatNvmConfiguration , AdminGetLogPageLidRequestType ,
16+ AdminGetLogPageSupportedLogPagesResponse , AdminIdentifyActiveNamespaceIdListResponse ,
17+ AdminIdentifyAllocatedNamespaceIdListResponse , AdminIdentifyCnsRequestType ,
18+ AdminIdentifyControllerResponse ,
1819 AdminIdentifyNamespaceIdentificationDescriptorListResponse ,
1920 AdminIdentifyNvmIdentifyNamespaceResponse , AdminIoCqeGenericCommandStatus ,
2021 AdminIoCqeStatus , AdminIoCqeStatusType , AdminSanitizeConfiguration , ControllerListResponse ,
@@ -23,8 +24,8 @@ use crate::{
2324 SanitizeStateInformation , SanitizeStatus , SanitizeStatusLogPageResponse ,
2425 SmartHealthInformationLogPageResponse ,
2526 mi:: {
26- AdminCommandRequestHeader , AdminCommandResponseHeader , AdminNamespaceAttachmentRequest ,
27- AdminNamespaceManagementRequest , AdminSanitizeRequest ,
27+ AdminCommandRequestHeader , AdminCommandResponseHeader , AdminFormatNvmRequest ,
28+ AdminNamespaceAttachmentRequest , AdminNamespaceManagementRequest , AdminSanitizeRequest ,
2829 CompositeControllerStatusDataStructureResponse , CompositeControllerStatusFlagSet ,
2930 ControllerFunctionAndReportingFlags , ControllerHealthDataStructure ,
3031 ControllerHealthStatusPollResponse , ControllerInformationResponse ,
@@ -810,6 +811,9 @@ impl RequestHandler for AdminCommandRequestHeader {
810811 AdminCommandRequestType :: NamespaceManagement ( req) => {
811812 req. handle ( ctx, mep, subsys, rest, resp, app) . await
812813 }
814+ AdminCommandRequestType :: FormatNvm ( req) => {
815+ req. handle ( ctx, mep, subsys, rest, resp, app) . await
816+ }
813817 AdminCommandRequestType :: Sanitize ( req) => {
814818 req. handle ( ctx, mep, subsys, rest, resp, app) . await
815819 }
@@ -1339,7 +1343,7 @@ impl RequestHandler for AdminIdentifyRequest {
13391343 . expect ( "Too many namespaces" ) ,
13401344 oncs : 0 ,
13411345 fuses : 0 ,
1342- fna : 0 ,
1346+ fna : ctlr . fna . into ( ) ,
13431347 vwc : 0 ,
13441348 awun : 0 ,
13451349 awupf : 0 ,
@@ -1813,6 +1817,53 @@ impl RequestHandler for AdminSanitizeRequest {
18131817 }
18141818}
18151819
1820+ impl RequestHandler for AdminFormatNvmRequest {
1821+ type Ctx = AdminCommandRequestHeader ;
1822+
1823+ async fn handle < A , C > (
1824+ & self ,
1825+ ctx : & Self :: Ctx ,
1826+ _mep : & mut crate :: ManagementEndpoint ,
1827+ subsys : & mut crate :: Subsystem ,
1828+ rest : & [ u8 ] ,
1829+ resp : & mut C ,
1830+ _app : A ,
1831+ ) -> Result < ( ) , ResponseStatus >
1832+ where
1833+ A : AsyncFnMut ( CommandEffect ) -> Result < ( ) , CommandEffectError > ,
1834+ C : AsyncRespChannel ,
1835+ {
1836+ if !rest. is_empty ( ) {
1837+ debug ! ( "Invalid request size for Admin Format NVM" ) ;
1838+ return Err ( ResponseStatus :: InvalidCommandSize ) ;
1839+ }
1840+
1841+ let Some ( ctlr) = subsys. ctlrs . iter ( ) . find ( |c| c. id . 0 == ctx. ctlid ) else {
1842+ debug ! ( "Unrecognised CTLID: {}" , ctx. ctlid) ;
1843+ return Err ( ResponseStatus :: InvalidParameter ) ;
1844+ } ;
1845+
1846+ let Ok ( config) = TryInto :: < AdminFormatNvmConfiguration > :: try_into ( self . config ) else {
1847+ debug ! ( "Invalid configuration for Admin Format NVM" ) ;
1848+ return Err ( ResponseStatus :: InvalidParameter ) ;
1849+ } ;
1850+
1851+ if config. lbafi != 0 {
1852+ debug ! ( "Unsupported LBA format index: {}" , config. lbafi) ;
1853+ return Err ( ResponseStatus :: InvalidParameter ) ;
1854+ }
1855+
1856+ if !ctlr. active_ns . iter ( ) . any ( |ns| ns. 0 == self . nsid ) && self . nsid != u32:: MAX {
1857+ debug ! ( "Unrecognised NSID: {}" , self . nsid) ;
1858+ return Err ( ResponseStatus :: InvalidParameter ) ;
1859+ }
1860+
1861+ // TODO: handle config.ses
1862+
1863+ admin_send_response_body ( resp, & [ ] ) . await
1864+ }
1865+ }
1866+
18161867impl crate :: ManagementEndpoint {
18171868 fn update ( & mut self , subsys : & crate :: Subsystem ) {
18181869 assert ! ( subsys. ctlrs. len( ) <= self . mecss. len( ) ) ;
0 commit comments