diff --git a/Cargo.lock b/Cargo.lock index 9c56aa7049..d93fb99f01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -839,7 +839,7 @@ dependencies = [ "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (git+https://gitlab.redox-os.org/redox-os/syscall.git)", "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.51 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1018,10 +1018,11 @@ dependencies = [ [[package]] name = "redox-log" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/redox-log.git#2e887e91e34edc90a2341678781e9271e70bc210" +source = "git+https://gitlab.redox-os.org/redox-os/redox-log.git#08693d48b2d7b56fcb07a1e62e257bacce749cef" dependencies = [ "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1207,7 +1208,7 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1702,7 +1703,7 @@ dependencies = [ "redox_event 0.1.0 (git+https://gitlab.redox-os.org/redox-os/event.git)", "redox_syscall 0.1.56 (git+https://gitlab.redox-os.org/redox-os/syscall.git)", "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.51 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1837,7 +1838,7 @@ dependencies = [ "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)" = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399" "checksum serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)" = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c" -"checksum serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "78a7a12c167809363ec3bd7329fc0a3369056996de43c4b37ef3cd54a6ce4867" +"checksum serde_json 1.0.51 (registry+https://github.com/rust-lang/crates.io-index)" = "da07b57ee2623368351e9a0488bb0b261322a15a6e0ae53e243cbdc0f4208da9" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" "checksum smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc" diff --git a/xhcid/src/driver_interface.rs b/xhcid/src/driver_interface.rs index 1d0968f402..8b560a5cd1 100644 --- a/xhcid/src/driver_interface.rs +++ b/xhcid/src/driver_interface.rs @@ -14,7 +14,7 @@ use thiserror::Error; pub use crate::usb::{EndpointTy, ENDP_ATTR_TY_MASK}; -#[derive(Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub struct ConfigureEndpointsReq { /// Index into the configuration descriptors of the device descriptor. pub config_desc: u8, diff --git a/xhcid/src/main.rs b/xhcid/src/main.rs index fedea2b399..f8dfd8c520 100644 --- a/xhcid/src/main.rs +++ b/xhcid/src/main.rs @@ -92,7 +92,7 @@ fn main() { match redox_log::RedoxLogger::new("usb", "host", "xhci.log") { Ok(logger) => match logger.with_stdout_mirror().enable() { - Ok(()) => { + Ok(_) => { println!("xhcid: enabled logger"); log::set_max_level(log::LevelFilter::Trace); } diff --git a/xhcid/src/xhci/scheme.rs b/xhcid/src/xhci/scheme.rs index 9289880953..70ea13db4e 100644 --- a/xhcid/src/xhci/scheme.rs +++ b/xhcid/src/xhci/scheme.rs @@ -288,10 +288,10 @@ impl Xhci { where D: FnMut(&mut Trb, bool) -> ControlFlow, { - let mut port_state = self.port_state_mut(port_num)?; - let slot = port_state.slot; + let (future, slot) = { + let mut port_state = self.port_state_mut(port_num)?; + let slot = port_state.slot; - let future = { let mut endpoint_state = port_state .endpoint_states .get_mut(&0).ok_or(Error::new(EIO))?; @@ -322,7 +322,7 @@ impl Xhci { let ent = false; cmd.status(interrupter, tk == TransferKind::In, ioc, ch, ent, cycle); - self.next_transfer_event_trb(RingId::default_control_pipe(port_num as u8), ring, &ring.trbs[last_index]) + (self.next_transfer_event_trb(RingId::default_control_pipe(port_num as u8), ring, &ring.trbs[last_index]), slot) }; self.dbs.lock().unwrap()[usize::from(slot)].write(Self::def_control_endp_doorbell()); @@ -423,6 +423,8 @@ impl Xhci { Ok(event_trb) } async fn device_req_no_data(&self, port: usize, req: usb::Setup) -> Result<()> { + trace!("DEVICE_REQ_NO_DATA port {}, req: {:?}", port, req); + self.execute_control_transfer( port, req, @@ -433,6 +435,7 @@ impl Xhci { Ok(()) } async fn set_configuration(&self, port: usize, config: u8) -> Result<()> { + debug!("Setting configuration value {} to port {}", config, port); self.device_req_no_data(port, usb::Setup::set_configuration(config)).await } async fn set_interface( @@ -441,6 +444,7 @@ impl Xhci { interface_num: u8, alternate_setting: u8, ) -> Result<()> { + debug!("Setting interface value {} (alternate setting {}) to port {}", interface_num, alternate_setting, port); self.device_req_no_data( port, usb::Setup::set_interface(interface_num, alternate_setting), @@ -556,6 +560,8 @@ impl Xhci { let mut req: ConfigureEndpointsReq = serde_json::from_slice(json_buf).or(Err(Error::new(EBADMSG)))?; + debug!("Running configure endpoints command, at port {}, request: {:?}", port, req); + if (!self.cap.cic() || !self.op.lock().unwrap().cie()) && (req.config_desc != 0 || req.interface_desc != None || req.alternate_setting != None) { @@ -623,7 +629,7 @@ impl Xhci { for endp_idx in 0..endp_desc_count as u8 { let endp_num = endp_idx + 1; - let port_state = self.port_states.get(&port).ok_or(Error::new(EBADFD))?; + let mut port_state = self.port_states.get_mut(&port).ok_or(Error::new(EBADFD))?; let dev_desc = port_state.dev_desc.as_ref().unwrap(); let endpoints = &dev_desc.config_descs.get(usize::from(req.config_desc)).ok_or(Error::new(EBADFD))?.interface_descs.get(usize::from(req.interface_desc.unwrap_or(0))).ok_or(Error::new(EBADFD))?.endpoints; let endp_desc = endpoints.get(endp_idx as usize).ok_or(Error::new(EIO))?; @@ -683,8 +689,6 @@ impl Xhci { assert_eq!(max_error_count & 0x3, max_error_count); assert_ne!(ep_ty, 0); // 0 means invalid. - let mut port_state = self.port_states.get_mut(&port).ok_or(Error::new(EBADFD))?; - let ring_ptr = if usb_log_max_streams.is_some() { let mut array = StreamContextArray::new(1 << (primary_streams + 1))?; @@ -726,7 +730,6 @@ impl Xhci { }; assert_eq!(primary_streams & 0x1F, primary_streams); - let port_state = self.port_states.get_mut(&port).ok_or(Error::new(EBADFD))?; let mut input_context = port_state.input_context.lock().unwrap(); input_context.add_context.writef(1 << endp_num_xhc, true); @@ -755,16 +758,19 @@ impl Xhci { .write(u32::from(avg_trb_len) | (u32::from(max_esit_payload_lo) << 16)); } - let port_state = self.port_states.get(&port).ok_or(Error::new(EBADFD))?; - let slot = port_state.slot; - let input_context_physical = port_state.input_context.lock().unwrap().physical(); + { + let port_state = self.port_states.get(&port).ok_or(Error::new(EBADFD))?; + let slot = port_state.slot; + let input_context_physical = port_state.input_context.lock().unwrap().physical(); - let (event_trb, command_trb) = self.execute_command(|trb, cycle| { - trb.configure_endpoint(slot, input_context_physical, cycle) - }).await; - self.event_handler_finished(); + let (event_trb, command_trb) = self.execute_command(|trb, cycle| { + trb.configure_endpoint(slot, input_context_physical, cycle) + }).await; - handle_event_trb("CONFIGURE_ENDPOINT", &event_trb, &command_trb)?; + self.event_handler_finished(); + + handle_event_trb("CONFIGURE_ENDPOINT", &event_trb, &command_trb)?; + } // Tell the device about this configuration. self.set_configuration(port, configuration_value).await?;