1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
//! Command TRBs.

use super::Link;
use bit_field::BitField;
use core::convert::TryInto;

allowed! {
    /// TRBs which are allowed to be pushed to the Command Ring.
    enum {
        /// Link TRB
        Link,
        /// Enable Slot Command TRB
        EnableSlot,
        /// Disable Slot Command TRB
        DisableSlot,
        /// Address Device Command TRB
        AddressDevice,
        /// Configure Endpoint Command TRB
        ConfigureEndpoint,
        /// Evaluate Context Command TRB
        EvaluateContext,
        /// Reset Endpoint Command TRB
        ResetEndpoint,
        /// Stop Endpoint Command TRB
        StopEndpoint,
        /// Set TR Dequeue Pointer Command TRB
        SetTrDequeuePointer,
        /// Reset Device Command TRB
        ResetDevice,
        /// Force Event Command TRB
        ForceEvent,
        /// Negotiate Bandwidth Command TRB
        NegotiateBandwidth,
        /// Set Latency Tolerance Value Command TRB
        SetLatencyToleranceValue,
        /// Get Port Bandwidth Command TRB
        GetPortBandwidth,
        /// Force Header Command TRB
        ForceHeader,
        /// No Op Command TRB
        Noop,
        /// Get Extended Property Command TRB
        GetExtendedProperty,
        /// Set Extended Property Command TRB
        SetExtendedProperty
    }
}

add_trb_with_default!(Noop, "No Op Command TRB", Type::NoopCommand);
impl_debug_for_trb!(Noop {});

add_trb_with_default!(EnableSlot, "Enable Slot Command TRB", Type::EnableSlot);
impl EnableSlot {
    /// Sets the value of the Slot Type field.
    pub fn set_slot_type(&mut self, t: u8) -> &mut Self {
        self.0[3].set_bits(16..=20, t.into());
        self
    }

    /// Returns the value of the Slot Type field.
    #[must_use]
    pub fn slot_type(&self) -> u8 {
        self.0[3].get_bits(16..=20).try_into().unwrap()
    }
}
impl_debug_for_trb!(EnableSlot { slot_type });

add_trb_with_default!(DisableSlot, "Disable Slot Command TRB", Type::DisableSlot);
impl DisableSlot {
    /// Sets the value of the Slot ID field.
    pub fn set_slot_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, i.into());
        self
    }

    /// Returns the value of the Slot ID field.
    #[must_use]
    pub fn slot_id(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(DisableSlot { slot_id });

add_trb_with_default!(
    AddressDevice,
    "Address Device Command TRB",
    Type::AddressDevice
);
impl AddressDevice {
    /// Sets the value of the Input Context Pointer field.
    ///
    /// # Panics
    ///
    /// This method panics if `p` is not 16-byte aligned.
    pub fn set_input_context_pointer(&mut self, p: u64) -> &mut Self {
        assert_eq!(
            p % 16,
            0,
            "The Input Context Pointer must be 16-byte aligned."
        );

        let l = p.get_bits(0..32);
        let u = p.get_bits(32..64);

        self.0[0] = l.try_into().unwrap();
        self.0[1] = u.try_into().unwrap();
        self
    }

    /// Returns the value of the Input Context Pointer field.
    #[must_use]
    pub fn input_context_pointer(&self) -> u64 {
        let l: u64 = self.0[0].into();
        let u: u64 = self.0[1].into();

        (u << 32) | l
    }

    /// Sets the value of the Block Set Address Request field.
    pub fn set_block_set_address_request(&mut self, r: bool) -> &mut Self {
        self.0[3].set_bit(9, r);
        self
    }

    /// Returns the value of the Block Set Address Request.
    #[must_use]
    pub fn block_set_address_request(&self) -> bool {
        self.0[3].get_bit(9)
    }

    /// Sets the value of the Slot ID field.
    pub fn set_slot_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, i.into());
        self
    }

    /// Returns the value of the Slot ID field.
    #[must_use]
    pub fn slot_id(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(AddressDevice {
    input_context_pointer,
    block_set_address_request,
    slot_id
});

add_trb_with_default!(
    ConfigureEndpoint,
    "Configure Endpoint Command TRB",
    Type::ConfigureEndpoint
);
impl ConfigureEndpoint {
    /// Sets the value of the Input Context Pointer field.
    ///
    /// # Panics
    ///
    /// This method panics if `p` is not 16-byte aligned.
    pub fn set_input_context_pointer(&mut self, p: u64) -> &mut Self {
        assert_eq!(
            p % 16,
            0,
            "The Input Context Pointer must be 16-byte aligned."
        );

        let l = p.get_bits(0..32);
        let u = p.get_bits(32..64);

        self.0[0] = l.try_into().unwrap();
        self.0[1] = u.try_into().unwrap();
        self
    }

    /// Returns the value of the Input Context Pointer field.
    #[must_use]
    pub fn input_context_pointer(&self) -> u64 {
        let l: u64 = self.0[0].into();
        let u: u64 = self.0[1].into();

        (u << 32) | l
    }

    /// Sets the value of the Deconfigure field.
    pub fn set_deconfigure(&mut self, d: bool) -> &mut Self {
        self.0[3].set_bit(9, d);
        self
    }

    /// Returns the value of the Deconfigure field.
    #[must_use]
    pub fn deconfigure(&self) -> bool {
        self.0[3].get_bit(9)
    }

    /// Sets the value of the Slot ID field.
    pub fn set_slot_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, i.into());
        self
    }

    /// Returns the value of the Slot ID field.
    #[must_use]
    pub fn slot_id(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(ConfigureEndpoint {
    input_context_pointer,
    deconfigure,
    slot_id
});

add_trb_with_default!(
    EvaluateContext,
    "Evaluate Context Command TRB",
    Type::EvaluateContext
);
impl EvaluateContext {
    /// Sets the value of the Input Context Pointer field.
    ///
    /// # Panics
    ///
    /// This method panics if `p` is not 16-byte aligned.
    pub fn set_input_context_pointer(&mut self, p: u64) -> &mut Self {
        assert_eq!(
            p % 16,
            0,
            "The Input Context Pointer must be 16-byte aligned."
        );

        let l = p.get_bits(0..32);
        let u = p.get_bits(32..64);

        self.0[0] = l.try_into().unwrap();
        self.0[1] = u.try_into().unwrap();
        self
    }

    /// Returns the value of the Input Context Pointer field.
    #[must_use]
    pub fn input_context_pointer(&self) -> u64 {
        let l: u64 = self.0[0].into();
        let u: u64 = self.0[1].into();

        (u << 32) | l
    }

    /// Sets the value of the Slot ID field.
    pub fn set_slot_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, i.into());
        self
    }

    /// Returns the value of the Slot ID field.
    #[must_use]
    pub fn slot_id(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(EvaluateContext {
    input_context_pointer,
    slot_id
});

add_trb_with_default!(
    ResetEndpoint,
    "Reset Endpoint Command TRB",
    Type::ResetEndpoint
);
impl ResetEndpoint {
    /// Sets the value of the Transfer State Preserve field.
    pub fn set_transfer_state_preserve(&mut self, tsp: bool) -> &mut Self {
        self.0[3].set_bit(9, tsp);
        self
    }

    /// Returns the value of the Transfer State Preserve field.
    #[must_use]
    pub fn transfer_state_preserve(&self) -> bool {
        self.0[3].get_bit(9)
    }

    /// Sets the value of the Endpoint ID field.
    pub fn set_endpoint_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(16..=20, i.into());
        self
    }

    /// Returns the value of the Endpoint ID.
    #[must_use]
    pub fn endpoint_id(&self) -> u8 {
        self.0[3].get_bits(16..=20).try_into().unwrap()
    }

    /// Sets the value of the Slot ID field.
    pub fn set_slot_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, i.into());
        self
    }

    /// Returns the value of the Slot ID field.
    #[must_use]
    pub fn slot_id(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(ResetEndpoint {
    transfer_state_preserve,
    endpoint_id,
    slot_id
});

add_trb_with_default!(
    StopEndpoint,
    "Stop Endpoint Command TRB",
    Type::StopEndpoint
);
impl StopEndpoint {
    /// Sets the value of the Endpoint ID field.
    pub fn set_endpoint_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(16..=20, i.into());
        self
    }

    /// Returns the value of the Endpoint ID field.
    #[must_use]
    pub fn endpoint_id(&self) -> u8 {
        self.0[3].get_bits(16..=20).try_into().unwrap()
    }

    /// Sets the value of the Suspend field.
    pub fn set_suspend(&mut self, s: bool) -> &mut Self {
        self.0[3].set_bit(23, s);
        self
    }

    /// Returns the value of the Suspend field.
    #[must_use]
    pub fn suspend(&self) -> bool {
        self.0[3].get_bit(23)
    }

    /// Sets the value of the Slot ID field.
    pub fn set_slot_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, i.into());
        self
    }

    /// Returns the value of the Slot ID field.
    #[must_use]
    pub fn slot_id(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(StopEndpoint {
    endpoint_id,
    suspend,
    slot_id
});

add_trb_with_default!(
    SetTrDequeuePointer,
    "Set TR Dequeue Pointer Command TRB",
    Type::SetTrDequeuePointer
);
impl SetTrDequeuePointer {
    /// Sets the value of the Dequeue Cycle State field.
    pub fn set_dequeue_cycle_state(&mut self, s: bool) -> &mut Self {
        self.0[0].set_bit(0, s);
        self
    }

    /// Returns the value of the Dequeue Cycle state field.
    #[must_use]
    pub fn dequeue_cycle_state(&self) -> bool {
        self.0[0].get_bit(0)
    }

    /// Sets the value of the Stream Context Type field.
    pub fn set_stream_context_type(&mut self, t: u8) -> &mut Self {
        self.0[0].set_bits(1..=3, t.into());
        self
    }

    /// Returns the value of the Stream Context Type field.
    #[must_use]
    pub fn stream_context_type(&self) -> u8 {
        self.0[0].get_bits(1..=3).try_into().unwrap()
    }

    /// Sets the value of the New TR Dequeue Pointer field.
    ///
    /// # Panics
    ///
    /// This method panics if `p` is not 16-byte aligned.
    pub fn set_new_tr_dequeue_pointer(&mut self, p: u64) -> &mut Self {
        assert_eq!(
            p % 16,
            0,
            "The New TR Dequeue Pointer must be 16-byte aligned."
        );

        let l = p.get_bits(0..32);
        let u = p.get_bits(32..64);

        self.0[0].set_bits(4..32, l.get_bits(4..32).try_into().unwrap());
        self.0[1] = u.try_into().unwrap();
        self
    }

    /// Returns the value of the New TR Dequeue Pointer field.
    #[must_use]
    pub fn new_tr_dequeue_pointer(&self) -> u64 {
        let l: u64 = self.0[0].into();
        let u: u64 = self.0[1].into();

        ((u << 32) | l) & 0xffff_fff0
    }

    /// Sets the value of the Stream ID field.
    pub fn set_stream_id(&mut self, i: u16) -> &mut Self {
        self.0[2].set_bits(16..=31, i.into());
        self
    }

    /// Returns the value of the Stream ID field.
    #[must_use]
    pub fn stream_id(&self) -> u16 {
        self.0[2].get_bits(16..=31).try_into().unwrap()
    }

    /// Sets the value of the Endpoint ID field.
    pub fn set_endpoint_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(16..=20, i.into());
        self
    }

    /// Returns the value of the Endpoint ID field.
    #[must_use]
    pub fn endpoint_id(&self) -> u8 {
        self.0[3].get_bits(16..=20).try_into().unwrap()
    }

    /// Sets the value of the Slot ID field.
    pub fn set_slot_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, i.into());
        self
    }

    /// Returns the value of the Slot ID field.
    #[must_use]
    pub fn slot_id(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(SetTrDequeuePointer {
    dequeue_cycle_state,
    stream_context_type,
    new_tr_dequeue_pointer,
    stream_id,
    endpoint_id,
    slot_id
});

add_trb_with_default!(ResetDevice, "Reset Device Command TRB", Type::ResetDevice);
impl ResetDevice {
    /// Sets the value of the Slot ID field.
    pub fn set_slot_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, i.into());
        self
    }

    /// Returns the value of the Slot ID field.
    #[must_use]
    pub fn slot_id(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(ResetDevice { slot_id });

add_trb_with_default!(ForceEvent, "Force Event Command TRB", Type::ForceEvent);
impl ForceEvent {
    /// Sets the value of the Event TRB Pointer field.
    ///
    /// # Panics
    ///
    /// This method panics if the `p` is not 16-byte aligned.
    pub fn set_event_trb_pointer(&mut self, p: u64) -> &mut Self {
        assert_eq!(p % 16, 0, "The Event TRB Pointer must be 16-byte aligned.");

        let l = p.get_bits(0..32);
        let u = p.get_bits(32..64);

        self.0[0] = l.try_into().unwrap();
        self.0[1] = u.try_into().unwrap();

        self
    }

    /// Returns the value of the Event TRB Pointer field.
    #[must_use]
    pub fn event_trb_pointer(&self) -> u64 {
        let l: u64 = self.0[0].into();
        let u: u64 = self.0[1].into();

        (u << 32) | l
    }

    /// Sets the value of the VF Interrupter Target field.
    pub fn set_vf_interrupter_target(&mut self, t: u16) -> &mut Self {
        self.0[2].set_bits(22..=31, t.into());
        self
    }

    /// Returns the value of the VF Interrupter Target field.
    #[must_use]
    pub fn vf_interrupter_target(&self) -> u16 {
        self.0[2].get_bits(22..=31).try_into().unwrap()
    }

    /// Sets the value of the VF ID field.
    pub fn set_vf_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(16..=23, i.into());
        self
    }

    /// Returns the value of the VF ID field.
    #[must_use]
    pub fn vf_id(&self) -> u8 {
        self.0[3].get_bits(16..=23).try_into().unwrap()
    }
}
impl_debug_for_trb!(ForceEvent {
    event_trb_pointer,
    vf_interrupter_target,
    vf_id
});

add_trb_with_default!(
    NegotiateBandwidth,
    "Negotiate Bandwidth Command TRB",
    Type::NegotiateBandwidth
);
impl NegotiateBandwidth {
    /// Sets the value of the Slot ID field.
    pub fn set_slot_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, i.into());
        self
    }

    /// Returns the value of the Slot ID field.
    #[must_use]
    pub fn slot_id(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(NegotiateBandwidth { slot_id });

add_trb_with_default!(
    SetLatencyToleranceValue,
    "Set Latency Tolerance Value Command TRB",
    Type::SetLatencyToleranceValue
);
impl SetLatencyToleranceValue {
    /// Sets the value of the Best Effort Latency Tolerance Value field.
    pub fn set_best_effort_latency_tolerance_value(&mut self, v: u16) -> &mut Self {
        self.0[3].set_bits(16..=27, v.into());
        self
    }

    /// Returns the value of the Best Effort Latency Tolerance Value field.
    #[must_use]
    pub fn best_effort_latency_tolerance_value(&self) -> u16 {
        self.0[3].get_bits(16..=27).try_into().unwrap()
    }
}
impl_debug_for_trb!(SetLatencyToleranceValue {
    best_effort_latency_tolerance_value
});

add_trb_with_default!(
    GetPortBandwidth,
    "Get Port Bandwidth Command TRB",
    Type::GetPortBandwidth
);
impl GetPortBandwidth {
    /// Sets the value of the Port Bandwidth Context Pointer field.
    ///
    /// # Panics
    ///
    /// This method panics if the `p` is not 16-byte aligned.
    pub fn set_port_bandwidth_context_pointer(&mut self, p: u64) -> &mut Self {
        assert_eq!(
            p % 16,
            0,
            "The Port Bandwidth Context Pointer must be 16-byte aligned."
        );

        let l = p.get_bits(0..32);
        let u = p.get_bits(32..64);

        self.0[0] = l.try_into().unwrap();
        self.0[1] = u.try_into().unwrap();
        self
    }

    /// Returns the value of the Port Bandwidth Context Pointer field.
    #[must_use]
    pub fn port_bandwidth_context_pointer(&self) -> u64 {
        let l: u64 = self.0[0].into();
        let u: u64 = self.0[1].into();

        (u << 32) | l
    }

    /// Sets the value of the Dev Speed field.
    pub fn set_dev_speed(&mut self, s: u8) -> &mut Self {
        self.0[3].set_bits(16..=19, s.into());
        self
    }

    /// Returns the value of the Dev Speed field.
    #[must_use]
    pub fn dev_speed(&self) -> u8 {
        self.0[3].get_bits(16..=19).try_into().unwrap()
    }

    /// Sets the value of the Hub Slot ID field.
    pub fn set_hub_slot_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, i.into());
        self
    }

    /// Returns the value of the Hub Slot ID field.
    #[must_use]
    pub fn hub_slot_id(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(GetPortBandwidth {
    port_bandwidth_context_pointer,
    dev_speed,
    hub_slot_id
});

add_trb_with_default!(ForceHeader, "Force Header Command TRB", Type::ForceHeader);
impl ForceHeader {
    /// Sets the value of the Packet Type field.
    pub fn set_packet_type(&mut self, t: u8) -> &mut Self {
        self.0[0].set_bits(0..=4, t.into());
        self
    }

    /// Returns the value of the Packet Type field.
    #[must_use]
    pub fn packet_type(&self) -> u8 {
        self.0[0].get_bits(0..=4).try_into().unwrap()
    }

    /// Sets the value of the Header Info field.
    ///
    /// # Panics
    ///
    /// This method panics if the lowest 5 bits of the `i[0]` are not 0.
    pub fn set_header_info(&mut self, info: [u32; 3]) -> &mut Self {
        assert!(
            info[0].trailing_zeros() >= 5,
            "The lowest 5 bits of the Header Info Low must be 0."
        );

        self.0[0].set_bits(5..=31, info[0].get_bits(5..=31));
        self.0[1] = info[1];
        self.0[2] = info[2];
        self
    }

    /// Returns the value of the Header Info field.
    #[must_use]
    pub fn header_info(&self) -> [u32; 3] {
        [self.0[0] & 0xffff_ffe0, self.0[1], self.0[2]]
    }

    /// Sets the value of the Root Hub Port Number.
    pub fn set_root_hub_port_number(&mut self, n: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, n.into());
        self
    }

    /// Returns the value of the Root Hub Port Number.
    #[must_use]
    pub fn root_hub_port_number(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(ForceHeader {
    packet_type,
    header_info,
    root_hub_port_number
});

add_trb_with_default!(
    GetExtendedProperty,
    "Get Extended Property Command TRB",
    Type::GetExtendedProperty
);
impl GetExtendedProperty {
    /// Sets the value of the Extended Property Context Pointer field.
    ///
    /// # Panics
    ///
    /// This method panics if the `p` is not 16-byte aligned.
    pub fn set_extended_property_context_pointer(&mut self, p: u64) -> &mut Self {
        assert_eq!(
            p % 16,
            0,
            "The Extended Property Context Pointer must be 16-byte aligned."
        );

        let l = p.get_bits(0..32);
        let u = p.get_bits(32..64);

        self.0[0] = l.try_into().unwrap();
        self.0[1] = u.try_into().unwrap();
        self
    }

    /// Returns the value of the Extended Property Context Pointer field.
    #[must_use]
    pub fn extended_property_context_pointer(&self) -> u64 {
        let l: u64 = self.0[0].into();
        let u: u64 = self.0[1].into();

        (u << 32) | l
    }

    /// Sets the value of the Extended Capability Identifier field.
    pub fn set_extended_capability_identifier(&mut self, eci: u16) -> &mut Self {
        self.0[2].set_bits(0..=15, eci.into());
        self
    }

    /// Returns the value of the Extended Capability Identifier field.
    #[must_use]
    pub fn extended_capability_identifier(&self) -> u16 {
        self.0[2].get_bits(0..=15).try_into().unwrap()
    }

    /// Sets the value of the Command Sub Type field.
    pub fn set_command_sub_type(&mut self, t: u8) -> &mut Self {
        self.0[3].set_bits(16..=18, t.into());
        self
    }

    /// Returns the value of the Command Sub Type field.
    #[must_use]
    pub fn command_sub_type(&self) -> u8 {
        self.0[3].get_bits(16..=18).try_into().unwrap()
    }

    /// Sets the value of the Endpoint ID field.
    pub fn set_endpoint_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(19..=23, i.into());
        self
    }

    /// Returns the value of the Endpoint ID field.
    #[must_use]
    pub fn endpoint_id(&self) -> u8 {
        self.0[3].get_bits(19..=23).try_into().unwrap()
    }

    /// Sets the value of the Slot ID field.
    pub fn set_slot_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, i.into());
        self
    }

    /// Returns the value of the Slot ID field.
    #[must_use]
    pub fn slot_id(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(GetExtendedProperty {
    extended_property_context_pointer,
    extended_capability_identifier,
    command_sub_type,
    endpoint_id,
    slot_id
});

add_trb_with_default!(
    SetExtendedProperty,
    "Set Extended Property Command TRB",
    Type::SetExtendedProperty
);
impl SetExtendedProperty {
    /// Sets the value of the Extended Capability Identifier field.
    pub fn set_extended_capability_identifier(&mut self, eci: u16) -> &mut Self {
        self.0[2].set_bits(0..=15, eci.into());
        self
    }

    /// Returns the value of the Extended Capability Identifier field.
    #[must_use]
    pub fn extended_capability_identifier(&self) -> u16 {
        self.0[2].get_bits(0..=15).try_into().unwrap()
    }

    /// Sets the value of the Capability Parameter field.
    pub fn set_capability_parameter(&mut self, p: u8) -> &mut Self {
        self.0[2].set_bits(15..=23, p.into());
        self
    }

    /// Returns the value of the Capability Parameter field.
    #[must_use]
    pub fn capability_parameter(&self) -> u8 {
        self.0[2].get_bits(15..=23).try_into().unwrap()
    }

    /// Sets the value of the Command Sub Type field.
    pub fn set_command_sub_type(&mut self, t: u8) -> &mut Self {
        self.0[3].set_bits(16..=18, t.into());
        self
    }

    /// Returns the value of the Command Sub Type field.
    #[must_use]
    pub fn command_sub_type(&self) -> u8 {
        self.0[3].get_bits(16..=18).try_into().unwrap()
    }

    /// Sets the value of the Endpoint ID field.
    pub fn set_endpoint_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(19..=23, i.into());
        self
    }

    /// Returns the value of the Endpoint ID field.
    #[must_use]
    pub fn endpoint_id(&self) -> u8 {
        self.0[3].get_bits(19..=23).try_into().unwrap()
    }

    /// Sets the value of the Slot ID field.
    pub fn set_slot_id(&mut self, i: u8) -> &mut Self {
        self.0[3].set_bits(24..=31, i.into());
        self
    }

    /// Returns the value of the Slot ID field.
    #[must_use]
    pub fn slot_id(&self) -> u8 {
        self.0[3].get_bits(24..=31).try_into().unwrap()
    }
}
impl_debug_for_trb!(SetExtendedProperty {
    extended_capability_identifier,
    capability_parameter,
    command_sub_type,
    endpoint_id,
    slot_id
});