From 59954829a2065d5d8b991f524b9bf61744dc5b4e Mon Sep 17 00:00:00 2001 From: occheung Date: Wed, 4 Sep 2024 10:00:48 +0800 Subject: [PATCH] drtio-proto: (N)ACK -> Reply { succeeded } --- src/libboard_artiq/src/drtioaux_proto.rs | 66 ++++++++++++++++++++---- src/runtime/src/mgmt.rs | 16 +++--- src/satman/src/main.rs | 35 +++++-------- 3 files changed, 79 insertions(+), 38 deletions(-) diff --git a/src/libboard_artiq/src/drtioaux_proto.rs b/src/libboard_artiq/src/drtioaux_proto.rs index 11e9cea..be40ddf 100644 --- a/src/libboard_artiq/src/drtioaux_proto.rs +++ b/src/libboard_artiq/src/drtioaux_proto.rs @@ -332,6 +332,16 @@ pub enum Packet { CoreMgmtAllocatorDebugRequest { destination: u8, }, + CoreMgmtFlashRequest { + destination: u8, + last: bool, + length: u16, + data: [u8; MASTER_PAYLOAD_MAX_SIZE], + }, + CoreMgmtDropLinkAck { + destination: u8, + }, + CoreMgmtDropLink, CoreMgmtGetLogReply { last: bool, length: u16, @@ -342,8 +352,9 @@ pub enum Packet { length: u16, value: [u8; SAT_PAYLOAD_MAX_SIZE], }, - CoreMgmtAck, - CoreMgmtNack, + CoreMgmtReply { + succeeded: bool, + }, } impl Packet { @@ -684,6 +695,23 @@ impl Packet { destination: reader.read_u8()?, }, 0xdb => { + let destination = reader.read_u8()?; + let last = reader.read_bool()?; + let length = reader.read_u16()?; + let mut data: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE]; + reader.read_exact(&mut data[0..length as usize])?; + Packet::CoreMgmtFlashRequest { + destination: destination, + last: last, + length: length, + data: data, + } + } + 0xdc => Packet::CoreMgmtDropLinkAck { + destination: reader.read_u8()?, + }, + 0xdd => Packet::CoreMgmtDropLink, + 0xde => { let last = reader.read_bool()?; let length = reader.read_u16()?; let mut data: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE]; @@ -694,7 +722,7 @@ impl Packet { data: data, } } - 0xdc => { + 0xdf => { let last = reader.read_bool()?; let length = reader.read_u16()?; let mut value: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE]; @@ -705,8 +733,9 @@ impl Packet { value: value, } } - 0xdd => Packet::CoreMgmtAck, - 0xde => Packet::CoreMgmtNack, + 0xe0 => Packet::CoreMgmtReply { + succeeded: reader.read_bool()?, + }, ty => return Err(Error::UnknownPacket(ty)), }) @@ -1153,20 +1182,39 @@ impl Packet { writer.write_u8(0xda)?; writer.write_u8(destination)?; } - Packet::CoreMgmtGetLogReply { last, length, data } => { + Packet::CoreMgmtFlashRequest { + destination, + last, + length, + data, + } => { writer.write_u8(0xdb)?; + writer.write_u8(destination)?; + writer.write_bool(last)?; + writer.write_u16(length)?; + writer.write_all(&data[..length as usize])?; + } + Packet::CoreMgmtDropLinkAck { destination } => { + writer.write_u8(0xdc)?; + writer.write_u8(destination)?; + } + Packet::CoreMgmtDropLink => writer.write_u8(0xdd)?, + Packet::CoreMgmtGetLogReply { last, length, data } => { + writer.write_u8(0xde)?; writer.write_bool(last)?; writer.write_u16(length)?; writer.write_all(&data[0..length as usize])?; } Packet::CoreMgmtConfigReadReply { last, length, value } => { - writer.write_u8(0xdc)?; + writer.write_u8(0xdf)?; writer.write_bool(last)?; writer.write_u16(length)?; writer.write_all(&value[0..length as usize])?; } - Packet::CoreMgmtAck => writer.write_u8(0xdd)?, - Packet::CoreMgmtNack => writer.write_u8(0xde)?, + Packet::CoreMgmtReply { succeeded } => { + writer.write_u8(0xe0)?; + writer.write_bool(succeeded)?; + } } Ok(()) } diff --git a/src/runtime/src/mgmt.rs b/src/runtime/src/mgmt.rs index bbcc8d9..275279f 100644 --- a/src/runtime/src/mgmt.rs +++ b/src/runtime/src/mgmt.rs @@ -201,7 +201,7 @@ mod remote_coremgmt { .await; match reply { - Ok(Packet::CoreMgmtAck) => { + Ok(Packet::CoreMgmtReply { succeeded: true }) => { write_i8(stream, Reply::Success as i8).await?; Ok(()) } @@ -291,7 +291,7 @@ mod remote_coremgmt { .await; match reply { - Ok(Packet::CoreMgmtAck) => { + Ok(Packet::CoreMgmtReply { succeeded: true }) => { write_i8(stream, Reply::Success as i8).await?; Ok(()) } @@ -330,7 +330,7 @@ mod remote_coremgmt { .await; match reply { - Ok(Packet::CoreMgmtAck) => { + Ok(Packet::CoreMgmtReply { succeeded: true }) => { write_i8(stream, Reply::Success as i8).await?; Ok(()) } @@ -440,7 +440,7 @@ mod remote_coremgmt { data: *slice, }, |reply| match reply { - Packet::CoreMgmtAck => Ok(()), + Packet::CoreMgmtReply { succeeded: true } => Ok(()), packet => { error!("received unexpected aux packet: {:?}", packet); Err(drtio::Error::UnexpectedReply) @@ -490,7 +490,7 @@ mod remote_coremgmt { .await; match reply { - Ok(Packet::CoreMgmtAck) => { + Ok(Packet::CoreMgmtReply { succeeded: true }) => { write_i8(stream, Reply::Success as i8).await?; Ok(()) } @@ -527,7 +527,7 @@ mod remote_coremgmt { .await; match reply { - Ok(Packet::CoreMgmtAck) => { + Ok(Packet::CoreMgmtReply { succeeded: true }) => { write_i8(stream, Reply::Success as i8).await?; Ok(()) } @@ -565,7 +565,7 @@ mod remote_coremgmt { .await; match reply { - Ok(Packet::CoreMgmtAck) => { + Ok(Packet::CoreMgmtReply { succeeded: true }) => { write_i8(stream, Reply::RebootImminent as i8).await?; Ok(()) } @@ -602,7 +602,7 @@ mod remote_coremgmt { .await; match reply { - Ok(Packet::CoreMgmtAck) => { + Ok(Packet::CoreMgmtReply { succeeded: true }) => { write_i8(stream, Reply::Success as i8).await?; Ok(()) } diff --git a/src/satman/src/main.rs b/src/satman/src/main.rs index 336a592..97e2112 100644 --- a/src/satman/src/main.rs +++ b/src/satman/src/main.rs @@ -1056,7 +1056,7 @@ fn process_aux_packet( timer ); mgmt::clear_log(); - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true }) } drtioaux::Packet::CoreMgmtSetLogLevelRequest { destination: _destination, @@ -1076,9 +1076,9 @@ fn process_aux_packet( if let Ok(level_filter) = mgmt::byte_to_level_filter(log_level) { info!("Changing log level to {}", level_filter); log::set_max_level(level_filter); - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true }) } else { - drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false }) } } drtioaux::Packet::CoreMgmtSetUartLogLevelRequest { @@ -1104,9 +1104,9 @@ fn process_aux_packet( .unwrap() .set_uart_log_level(level_filter); } - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true }) } else { - drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false }) } } drtioaux::Packet::CoreMgmtConfigReadRequest { @@ -1130,7 +1130,7 @@ fn process_aux_packet( let key_slice = &key[..length as usize]; if !key_slice.is_ascii() { error!("invalid key"); - drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false }) } else { let key = core::str::from_utf8(key_slice).unwrap(); if core_manager.fetch_config_value(key).is_ok() { @@ -1144,7 +1144,7 @@ fn process_aux_packet( }, ) } else { - drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false }) } } } @@ -1198,11 +1198,7 @@ fn process_aux_packet( core_manager.clear_data(); } - if succeeded { - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) - } else { - drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) - } + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded }) } drtioaux::Packet::CoreMgmtConfigRemoveRequest { destination: _destination, @@ -1223,14 +1219,11 @@ fn process_aux_packet( let key_slice = &key[..length as usize]; if !key_slice.is_ascii() { error!("invalid key"); - drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false }) } else { let key = core::str::from_utf8(key_slice).unwrap(); - if core_manager.remove_config(key).is_ok() { - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck) - } else { - drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) - } + let succeeded = core_manager.remove_config(key).is_ok(); + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded }) } } drtioaux::Packet::CoreMgmtConfigEraseRequest { @@ -1248,7 +1241,7 @@ fn process_aux_packet( ); error!("config erase not supported on zynq device"); - drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false }) } drtioaux::Packet::CoreMgmtRebootRequest { destination: _destination, @@ -1265,7 +1258,7 @@ fn process_aux_packet( timer ); - drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)?; + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: true })?; info!("reboot imminent"); slcr::reboot(); Ok(()) @@ -1285,7 +1278,7 @@ fn process_aux_packet( ); error!("debug allocator not supported on zynq device"); - drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack) + drtioaux::send(0, &drtioaux::Packet::CoreMgmtReply { succeeded: false }) } p => {