From dd4354316894c10009fe245bf5e5b084983e156a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 28 Jan 2026 17:33:25 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(device):=20update?= =?UTF-8?q?=20hub=20speed=20assignment=20logic=20and=20clean=20up=20commen?= =?UTF-8?q?ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usb-host/src/backend/kmod/hub/device.rs | 13 +++++++--- usb-host/src/backend/kmod/xhci/device.rs | 30 ++++++++++++++---------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/usb-host/src/backend/kmod/hub/device.rs b/usb-host/src/backend/kmod/hub/device.rs index 3a78358..9465407 100644 --- a/usb-host/src/backend/kmod/hub/device.rs +++ b/usb-host/src/backend/kmod/hub/device.rs @@ -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(_) => { @@ -271,7 +275,9 @@ impl HubDevice { } } } - HUB_PR_SS => {} + HUB_PR_SS => { + info.speed = Speed::SuperSpeed; + } _ => { warn!("Unknown hub protocol: {}", device_protocol); } @@ -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); diff --git a/usb-host/src/backend/kmod/xhci/device.rs b/usb-host/src/backend/kmod/xhci/device.rs index 2ab3861..f5a8138 100644 --- a/usb-host/src/backend/kmod/xhci/device.rs +++ b/usb-host/src/backend/kmod/xhci/device.rs @@ -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; @@ -230,6 +229,8 @@ 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; @@ -237,23 +238,26 @@ impl Device { break; } if matches!(parent_hub.speed, Speed::High) { + hs_parent = Some(p); break; } 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);