@@ -32,10 +32,11 @@ use crate::{
3232 ControllerPropertyFlags , MessageType , NvmSubsystemHealthDataStructureResponse ,
3333 NvmSubsystemInformationResponse , NvmeManagementResponse , NvmeMiCommandRequestHeader ,
3434 NvmeMiCommandRequestType , NvmeMiDataStructureManagementResponse ,
35- NvmeMiDataStructureRequestType , PciePortDataResponse , PortInformationResponse ,
36- TwoWirePortDataResponse ,
35+ NvmeMiDataStructureRequestType , PcieCommandRequestHeader , PciePortDataResponse ,
36+ PortInformationResponse , TwoWirePortDataResponse ,
3737 } ,
3838 } ,
39+ pcie:: PciDeviceFunctionConfigurationSpace ,
3940 wire:: { WireString , WireVec } ,
4041} ;
4142
@@ -121,6 +122,18 @@ impl RequestHandler for MessageHeader {
121122 }
122123 }
123124 }
125+ MessageType :: PcieCommand => {
126+ match & PcieCommandRequestHeader :: from_bytes ( ( rest, 0 ) ) {
127+ Ok ( ( ( rest, _) , ch) ) => ch. handle ( ch, mep, subsys, rest, resp, app) . await ,
128+ Err ( err) => {
129+ debug ! (
130+ "Unable to parse PcieCommandRequestHeader from message buffer: {err:?}"
131+ ) ;
132+ // TODO: This is a bad assumption: Can see DekuError::InvalidParam too
133+ Err ( ResponseStatus :: InvalidCommandSize )
134+ }
135+ }
136+ }
124137 _ => {
125138 debug ! ( "Unimplemented NMINT: {:?}" , ctx. nmimt( ) ) ;
126139 Err ( ResponseStatus :: InternalError )
@@ -2003,6 +2016,82 @@ impl RequestHandler for AdminFormatNvmRequest {
20032016 }
20042017}
20052018
2019+ impl RequestHandler for PcieCommandRequestHeader {
2020+ type Ctx = PcieCommandRequestHeader ;
2021+
2022+ async fn handle < A , C > (
2023+ & self ,
2024+ ctx : & Self :: Ctx ,
2025+ _mep : & mut crate :: ManagementEndpoint ,
2026+ subsys : & mut crate :: Subsystem ,
2027+ rest : & [ u8 ] ,
2028+ resp : & mut C ,
2029+ _app : A ,
2030+ ) -> Result < ( ) , ResponseStatus >
2031+ where
2032+ A : AsyncFnMut ( crate :: CommandEffect ) -> Result < ( ) , CommandEffectError > ,
2033+ C : mctp:: AsyncRespChannel ,
2034+ {
2035+ match & ctx. op {
2036+ super :: PcieCommandRequestType :: ConfigurationRead ( req) => {
2037+ if !rest. is_empty ( ) {
2038+ debug ! ( "Invalid request size for PcieCommand" ) ;
2039+ return Err ( ResponseStatus :: InvalidCommandSize ) ;
2040+ }
2041+
2042+ if req. length != 4096 {
2043+ debug ! ( "Implement length support" ) ;
2044+ return Err ( ResponseStatus :: InternalError ) ;
2045+ }
2046+
2047+ if req. offset != 0 {
2048+ debug ! ( "Implement offset support" ) ;
2049+ return Err ( ResponseStatus :: InternalError ) ;
2050+ }
2051+
2052+ let mh = MessageHeader :: respond ( MessageType :: PcieCommand ) . encode ( ) ?;
2053+
2054+ let status = [ 0u8 ; 4 ] ; /* Success */
2055+
2056+ let cr = PciDeviceFunctionConfigurationSpace :: builder ( )
2057+ . vid ( subsys. info . pci_vid )
2058+ . did ( subsys. info . pci_did )
2059+ . svid ( subsys. info . pci_svid )
2060+ . sdid ( subsys. info . pci_sdid )
2061+ . build ( )
2062+ . encode ( ) ?;
2063+
2064+ send_response ( resp, & [ & mh. 0 , & status, & cr. 0 ] ) . await ;
2065+ Ok ( ( ) )
2066+ }
2067+ super :: PcieCommandRequestType :: ConfigurationWrite ( req) => {
2068+ let response = if rest. len ( ) == req. length as usize {
2069+ debug ! ( "Unsupported write at {} for {}" , req. offset, req. length) ;
2070+ ResponseStatus :: AccessDenied
2071+ } else {
2072+ debug ! (
2073+ "Request data size {} does not match requested write size {}" ,
2074+ rest. len( ) ,
2075+ req. length
2076+ ) ;
2077+ ResponseStatus :: InvalidCommandInputDataSize
2078+ } ;
2079+
2080+ let mh = MessageHeader :: respond ( MessageType :: PcieCommand ) . encode ( ) ?;
2081+
2082+ let status = [ response. id ( ) , 0 , 0 , 0 ] ;
2083+
2084+ send_response ( resp, & [ & mh. 0 , & status] ) . await ;
2085+ Ok ( ( ) )
2086+ }
2087+ _ => {
2088+ debug ! ( "Unimplemented OPCODE: {:?}" , ctx. _opcode) ;
2089+ Err ( ResponseStatus :: InternalError )
2090+ }
2091+ }
2092+ }
2093+ }
2094+
20062095impl crate :: ManagementEndpoint {
20072096 fn update ( & mut self , subsys : & crate :: Subsystem ) {
20082097 assert ! ( subsys. ctlrs. len( ) <= self . mecss. len( ) ) ;
0 commit comments