Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions usb-host/src/backend/kmod/hub/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,15 @@ impl HubDevice {
let device_protocol = self.data.dev.descriptor().protocol;

match device_protocol {
HUB_PR_FS => {}
HUB_PR_FS => {
info.speed = Speed::Full;
}
HUB_PR_HS_SINGLE_TT => {
info.speed = Speed::High;
debug!("Hub is High Speed with Single TT");
}
HUB_PR_HS_MULTI_TT => {
info.speed = Speed::High;
debug!("Hub is High Speed with Multiple TTs");
match self.data.dev.claim_interface(0, 1).await {
Ok(_) => {
Expand All @@ -271,7 +275,9 @@ impl HubDevice {
}
}
}
HUB_PR_SS => {}
HUB_PR_SS => {
info.speed = Speed::SuperSpeed;
}
_ => {
warn!("Unknown hub protocol: {}", device_protocol);
}
Expand Down Expand Up @@ -756,7 +762,8 @@ impl HubDevice {
return Err(USBError::from("Device disconnected during enable wait"));
}

// self.kernel.delay(Duration::from_millis(CHECK_INTERVAL_MS));
self.kernel
.delay(Duration::from_millis(CHECK_INTERVAL_MS));
}

warn!("Port {} enable timeout after {}ms", port_id, MAX_WAIT_MS);
Expand Down
30 changes: 17 additions & 13 deletions usb-host/src/backend/kmod/xhci/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ impl Device {
// 直接使用 DeviceSpeed 枚举计算默认 max packet size
let max_packet_size = parse_default_max_packet_size_from_port_speed(info.port_speed);

// let route_string = info.route_string.raw();

// Route String 由拓扑决定(root hub 端口不计入)
let mut route_string = 0u32;
let mut parent_id = info.parent_hub;
let mut port_id = info.port_id;
Expand Down Expand Up @@ -230,30 +229,35 @@ impl Device {
if matches!(info.port_speed, Speed::Low | Speed::Full) {
let mut parent_id = info.parent_hub;
let mut tt_port = info.port_id;
let mut hs_parent = None;

while let Some(p) = parent_id {
let parent_hub = info.infos.get(&p).unwrap();
tt_port = parent_hub.port_id;
if parent_hub.hub_depth == -1 {
break;
}
if matches!(parent_hub.speed, Speed::High) {
hs_parent = Some(p);
break;
Comment on lines 234 to 242
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TT parent traversal overwrites tt_port with parent_hub.port_id before checking whether the current parent_hub is the HS hub. For a LS/FS device behind a HS hub (possibly through FS hubs), this makes parent_port_number end up as the HS hub’s upstream port number (port on its parent, e.g. root port) instead of the HS hub port that leads to the LS/FS device (or downstream FS hub). Consider keeping a separate child_port (initialized to info.port_id) and only updating it when moving up a non-HS hub; when parent_hub.speed is High, use the current child_port for set_parent_port_number.

Copilot uses AI. Check for mistakes.
}
parent_id = parent_hub.parent;
}

let parent = info.infos.get(&parent_id.unwrap()).unwrap();
let slot_id = parent.slot_id;
if parent.tt.multi {
slot_context.set_multi_tt();
}
if let Some(hs_id) = hs_parent {
let parent = info.infos.get(&hs_id).unwrap();
let slot_id = parent.slot_id;
if parent.tt.multi {
slot_context.set_multi_tt();
}

slot_context.set_parent_hub_slot_id(slot_id);
slot_context.set_parent_port_number(tt_port);
debug!(
"Setting parent_port_number (TT): {}, parent_hub_slot_id: {}",
tt_port, slot_id
);
slot_context.set_parent_hub_slot_id(slot_id);
slot_context.set_parent_port_number(tt_port);
debug!(
"Setting parent_port_number (TT): {}, parent_hub_slot_id: {}",
tt_port, slot_id
);
}
}

slot_context.set_tt_think_time(0);
Expand Down