11//! Command TRBs.
22
3- use super :: Link ;
3+ use super :: { Link , Type } ;
44use bit_field:: BitField ;
55use core:: convert:: TryInto ;
6+ use num_traits:: FromPrimitive ;
67
78allowed ! {
89 /// TRBs which are allowed to be pushed to the Command Ring.
@@ -45,17 +46,66 @@ allowed! {
4546 SetExtendedProperty
4647 }
4748}
49+ impl TryFrom < [ u32 ; 4 ] > for Allowed {
50+ type Error = [ u32 ; 4 ] ;
51+
52+ fn try_from ( raw : [ u32 ; 4 ] ) -> Result < Self , Self :: Error > {
53+ try_from ! (
54+ raw =>
55+ Link ,
56+ EnableSlot ,
57+ DisableSlot ,
58+ AddressDevice ,
59+ ConfigureEndpoint ,
60+ EvaluateContext ,
61+ ResetEndpoint ,
62+ StopEndpoint ,
63+ SetTrDequeuePointer ,
64+ ResetDevice ,
65+ ForceEvent ,
66+ NegotiateBandwidth ,
67+ SetLatencyToleranceValue ,
68+ GetPortBandwidth ,
69+ ForceHeader ,
70+ Noop ( Command ) ,
71+ GetExtendedProperty ,
72+ SetExtendedProperty ,
73+ ) ;
74+ Err ( raw)
75+ }
76+ }
4877
4978add_trb_with_default ! ( Noop , "No Op Command TRB" , Type :: NoopCommand ) ;
79+ reserved ! ( Noop ( Type :: NoopCommand ) {
80+ [ 0 ] 0 ..=31 ;
81+ [ 1 ] 0 ..=31 ;
82+ [ 2 ] 0 ..=31 ;
83+ [ 3 ] 1 ..=9 ;
84+ [ 3 ] 21 ..=31 ;
85+ } ) ;
5086impl_debug_for_trb ! ( Noop { } ) ;
5187
5288add_trb_with_default ! ( EnableSlot , "Enable Slot Command TRB" , Type :: EnableSlot ) ;
89+ reserved ! ( EnableSlot ( Type :: EnableSlot ) {
90+ [ 0 ] 0 ..=31 ;
91+ [ 1 ] 0 ..=31 ;
92+ [ 2 ] 0 ..=31 ;
93+ [ 3 ] 1 ..=9 ;
94+ [ 3 ] 21 ..=31 ;
95+ } ) ;
5396impl EnableSlot {
5497 rw_field ! ( [ 3 ] ( 16 ..=20 ) , slot_type, "Slot Type" , u8 ) ;
5598}
5699impl_debug_for_trb ! ( EnableSlot { slot_type } ) ;
57100
58101add_trb_with_default ! ( DisableSlot , "Disable Slot Command TRB" , Type :: DisableSlot ) ;
102+ reserved ! ( DisableSlot ( Type :: DisableSlot ) {
103+ [ 0 ] 0 ..=31 ;
104+ [ 1 ] 0 ..=31 ;
105+ [ 2 ] 0 ..=31 ;
106+ [ 3 ] 1 ..=9 ;
107+ [ 3 ] 16 ..=23 ;
108+ } ) ;
59109impl DisableSlot {
60110 rw_field ! ( [ 3 ] ( 24 ..=31 ) , slot_id, "Slot ID" , u8 ) ;
61111}
@@ -66,6 +116,12 @@ add_trb_with_default!(
66116 "Address Device Command TRB" ,
67117 Type :: AddressDevice
68118) ;
119+ reserved ! ( AddressDevice ( Type :: AddressDevice ) {
120+ [ 0 ] 0 ..=3 ;
121+ [ 2 ] 0 ..=31 ;
122+ [ 3 ] 1 ..=8 ;
123+ [ 3 ] 16 ..=23 ;
124+ } ) ;
69125impl AddressDevice {
70126 /// Sets the value of the Input Context Pointer field.
71127 ///
@@ -114,6 +170,12 @@ add_trb_with_default!(
114170 "Configure Endpoint Command TRB" ,
115171 Type :: ConfigureEndpoint
116172) ;
173+ reserved ! ( ConfigureEndpoint ( Type :: ConfigureEndpoint ) {
174+ [ 0 ] 0 ..=3 ;
175+ [ 2 ] 0 ..=31 ;
176+ [ 3 ] 1 ..=8 ;
177+ [ 3 ] 16 ..=23 ;
178+ } ) ;
117179impl ConfigureEndpoint {
118180 /// Sets the value of the Input Context Pointer field.
119181 ///
@@ -158,6 +220,12 @@ add_trb_with_default!(
158220 "Evaluate Context Command TRB" ,
159221 Type :: EvaluateContext
160222) ;
223+ reserved ! ( EvaluateContext ( Type :: EvaluateContext ) {
224+ [ 0 ] 0 ..=3 ;
225+ [ 2 ] 0 ..=31 ;
226+ [ 3 ] 1 ..=8 ;
227+ [ 3 ] 16 ..=23 ;
228+ } ) ;
161229impl EvaluateContext {
162230 /// Sets the value of the Input Context Pointer field.
163231 ///
@@ -199,6 +267,13 @@ add_trb_with_default!(
199267 "Reset Endpoint Command TRB" ,
200268 Type :: ResetEndpoint
201269) ;
270+ reserved ! ( ResetEndpoint ( Type :: ResetEndpoint ) {
271+ [ 0 ] 0 ..=31 ;
272+ [ 1 ] 0 ..=31 ;
273+ [ 2 ] 0 ..=31 ;
274+ [ 3 ] 1 ..=8 ;
275+ [ 3 ] 21 ..=23 ;
276+ } ) ;
202277impl ResetEndpoint {
203278 rw_bit ! ( [ 3 ] ( 9 ) , transfer_state_preserve, "Transfer State Preserve" ) ;
204279 rw_field ! ( [ 3 ] ( 16 ..=20 ) , endpoint_id, "Endpoint ID" , u8 ) ;
@@ -215,6 +290,13 @@ add_trb_with_default!(
215290 "Stop Endpoint Command TRB" ,
216291 Type :: StopEndpoint
217292) ;
293+ reserved ! ( StopEndpoint ( Type :: StopEndpoint ) {
294+ [ 0 ] 0 ..=31 ;
295+ [ 1 ] 0 ..=31 ;
296+ [ 2 ] 0 ..=31 ;
297+ [ 3 ] 1 ..=9 ;
298+ [ 3 ] 21 ..=22 ;
299+ } ) ;
218300impl StopEndpoint {
219301 rw_field ! ( [ 3 ] ( 16 ..=20 ) , endpoint_id, "Endpoint ID" , u8 ) ;
220302 rw_bit ! ( [ 3 ] ( 23 ) , suspend, "Suspend" ) ;
@@ -231,6 +313,11 @@ add_trb_with_default!(
231313 "Set TR Dequeue Pointer Command TRB" ,
232314 Type :: SetTrDequeuePointer
233315) ;
316+ reserved ! ( SetTrDequeuePointer ( Type :: SetTrDequeuePointer ) {
317+ [ 2 ] 0 ..=15 ;
318+ [ 3 ] 1 ..=9 ;
319+ [ 3 ] 21 ..=23 ;
320+ } ) ;
234321impl SetTrDequeuePointer {
235322 rw_bit ! ( [ 0 ] ( 0 ) , dequeue_cycle_state, "Dequeue Cycle State" ) ;
236323 rw_field ! ( [ 0 ] ( 1 ..=3 ) , stream_context_type, "Stream Context Type" , u8 ) ;
@@ -278,12 +365,25 @@ impl_debug_for_trb!(SetTrDequeuePointer {
278365} ) ;
279366
280367add_trb_with_default ! ( ResetDevice , "Reset Device Command TRB" , Type :: ResetDevice ) ;
368+ reserved ! ( ResetDevice ( Type :: ResetDevice ) {
369+ [ 0 ] 0 ..=31 ;
370+ [ 1 ] 0 ..=31 ;
371+ [ 2 ] 0 ..=31 ;
372+ [ 3 ] 1 ..=9 ;
373+ [ 3 ] 16 ..=23 ;
374+ } ) ;
281375impl ResetDevice {
282376 rw_field ! ( [ 3 ] ( 24 ..=31 ) , slot_id, "Slot ID" , u8 ) ;
283377}
284378impl_debug_for_trb ! ( ResetDevice { slot_id } ) ;
285379
286380add_trb_with_default ! ( ForceEvent , "Force Event Command TRB" , Type :: ForceEvent ) ;
381+ reserved ! ( ForceEvent ( Type :: ForceEvent ) {
382+ [ 0 ] 0 ..=3 ;
383+ [ 2 ] 0 ..=21 ;
384+ [ 3 ] 1 ..=9 ;
385+ [ 3 ] 24 ..=31 ;
386+ } ) ;
287387impl ForceEvent {
288388 /// Sets the value of the Event TRB Pointer field.
289389 ///
@@ -330,6 +430,13 @@ add_trb_with_default!(
330430 "Negotiate Bandwidth Command TRB" ,
331431 Type :: NegotiateBandwidth
332432) ;
433+ reserved ! ( NegotiateBandwidth ( Type :: NegotiateBandwidth ) {
434+ [ 0 ] 0 ..=31 ;
435+ [ 1 ] 0 ..=31 ;
436+ [ 2 ] 0 ..=31 ;
437+ [ 3 ] 1 ..=9 ;
438+ [ 3 ] 16 ..=23 ;
439+ } ) ;
333440impl NegotiateBandwidth {
334441 rw_field ! ( [ 3 ] ( 24 ..=31 ) , slot_id, "Slot ID" , u8 ) ;
335442}
@@ -340,6 +447,13 @@ add_trb_with_default!(
340447 "Set Latency Tolerance Value Command TRB" ,
341448 Type :: SetLatencyToleranceValue
342449) ;
450+ reserved ! ( SetLatencyToleranceValue ( Type :: SetLatencyToleranceValue ) {
451+ [ 0 ] 0 ..=31 ;
452+ [ 1 ] 0 ..=31 ;
453+ [ 2 ] 0 ..=31 ;
454+ [ 3 ] 1 ..=9 ;
455+ [ 3 ] 28 ..=31 ;
456+ } ) ;
343457impl SetLatencyToleranceValue {
344458 rw_field ! (
345459 [ 3 ] ( 16 ..=27 ) ,
@@ -357,6 +471,12 @@ add_trb_with_default!(
357471 "Get Port Bandwidth Command TRB" ,
358472 Type :: GetPortBandwidth
359473) ;
474+ reserved ! ( GetPortBandwidth ( Type :: GetPortBandwidth ) {
475+ [ 0 ] 0 ..=3 ;
476+ [ 2 ] 0 ..=31 ;
477+ [ 3 ] 1 ..=9 ;
478+ [ 3 ] 20 ..=23 ;
479+ } ) ;
360480impl GetPortBandwidth {
361481 /// Sets the value of the Port Bandwidth Context Pointer field.
362482 ///
@@ -396,6 +516,10 @@ impl_debug_for_trb!(GetPortBandwidth {
396516} ) ;
397517
398518add_trb_with_default ! ( ForceHeader , "Force Header Command TRB" , Type :: ForceHeader ) ;
519+ reserved ! ( ForceHeader ( Type :: ForceHeader ) {
520+ [ 3 ] 1 ..=9 ;
521+ [ 3 ] 16 ..=23 ;
522+ } ) ;
399523impl ForceHeader {
400524 rw_field ! ( [ 0 ] ( 0 ..=4 ) , packet_type, "Packet Type" , u8 ) ;
401525
@@ -440,6 +564,11 @@ add_trb_with_default!(
440564 "Get Extended Property Command TRB" ,
441565 Type :: GetExtendedProperty
442566) ;
567+ reserved ! ( GetExtendedProperty ( Type :: GetExtendedProperty ) {
568+ [ 0 ] 0 ..=3 ;
569+ [ 2 ] 16 ..=31 ;
570+ [ 3 ] 1 ..=9 ;
571+ } ) ;
443572impl GetExtendedProperty {
444573 /// Sets the value of the Extended Property Context Pointer field.
445574 ///
@@ -493,6 +622,12 @@ add_trb_with_default!(
493622 "Set Extended Property Command TRB" ,
494623 Type :: SetExtendedProperty
495624) ;
625+ reserved ! ( SetExtendedProperty ( Type :: SetExtendedProperty ) {
626+ [ 0 ] 0 ..=31 ;
627+ [ 1 ] 0 ..=31 ;
628+ [ 2 ] 24 ..=31 ;
629+ [ 3 ] 1 ..=9 ;
630+ } ) ;
496631impl SetExtendedProperty {
497632 rw_field ! (
498633 [ 2 ] ( 0 ..=15 ) ,
0 commit comments