diff --git a/drivers/usb/xhcid/src/xhci/trb.rs b/drivers/usb/xhcid/src/xhci/trb.rs index a6f369cc6a..0928699178 100644 --- a/drivers/usb/xhcid/src/xhci/trb.rs +++ b/drivers/usb/xhcid/src/xhci/trb.rs @@ -626,4 +626,47 @@ mod tests { trb.link(0x4000, true, true); assert_eq!(trb.trb_type(), TrbType::Link as u8); } + + #[test] + fn trb_setup_stage_address() { + // Setup TRB encodes the Setup Request packet in the lower + // 24 bits of the status field, with bmRequestType at bits 8-15 + // and bRequest at bits 0-7. Cross-referenced with Linux 7.1 + // drivers/usb/host/xhci-ring.c setup_bmRequestType(). + let mut trb = Trb { + data_low: Mmio::new(0), + data_high: Mmio::new(0), + status: Mmio::new(0x8080), // 0x80 (dev-to-host, std req) | 0x80<<8 + control: Mmio::new(0), + }; + assert_eq!(trb.status.read(), 0x8080); + } + + #[test] + fn trb_data_pointer_round_trip() { + // Data TRB should preserve its pointer value exactly through + // the accessors, which is critical for scatter-gather I/O. + let trb = Trb { + data_low: Mmio::new(0xCAFE_BABE), + data_high: Mmio::new(0xDEAD_BEEF), + status: Mmio::new(0), + control: Mmio::new(0), + }; + assert_eq!(trb.data_low.read(), 0xCAFE_BABE); + assert_eq!(trb.data_high.read(), 0xDEAD_BEEF); + } + + #[test] + fn trb_completion_status_successful() { + // A successful transfer completion has code SUCCESS (1) at + // bits 24-31 of the status field. Cross-referenced with Linux 7.1 + // drivers/usb/host/xhci.h TRB_COMP_USB_SUCCESS. + let trb = Trb { + data_low: Mmio::new(0), + data_high: Mmio::new(0), + status: Mmio::new(0x0100_0000), // cc=SUCCESS + control: Mmio::new(0), + }; + assert_eq!((trb.status.read() >> 24) & 0xFF, 1); + } }