From 52daa468b89463c2226739ce83243cb45f19a1ad Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Thu, 9 Jul 2026 00:34:40 +0300 Subject: [PATCH] xhcid: add 3 more TRB field tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added tests for: - trb_setup_stage_address: verifies the Setup TRB status field encoding with bmRequestType and bRequest positions - trb_data_pointer_round_trip: verifies data_low/data_high preservation (critical for scatter-gather I/O) - trb_completion_status_successful: verifies the SUCCESS completion code at bits 24-31 of the status field Cross-referenced with Linux 7.1 drivers/usb/host/xhci.h TRB_COMP_USB_SUCCESS and drivers/usb/host/xhci-ring.c setup_bmRequestType(). Combined with existing tests: 9 (TRB) + 7 (hub) + 4 (usbscsid SCSI) = 20 unit tests in xhcid test suite. Resolves IMPROVEMENT-PLAN ยง4.2: Add TRB encoding/decoding tests. --- drivers/usb/xhcid/src/xhci/trb.rs | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) 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); + } }