xhcid: add 3 more TRB field tests

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.
This commit is contained in:
Red Bear OS
2026-07-09 00:34:40 +03:00
parent baea0e523b
commit 52daa468b8
+43
View File
@@ -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);
}
}