drtio-mgmt: remove custom payload size

This commit is contained in:
occheung 2024-08-23 11:37:55 +08:00
parent 006981306f
commit 1683572838
5 changed files with 29 additions and 31 deletions

View File

@ -8,11 +8,6 @@ const MAX_PACKET: usize = 1024;
pub const SAT_PAYLOAD_MAX_SIZE: usize = /*max size*/MAX_PACKET - /*CRC*/4 - /*packet ID*/1 - /*last*/1 - /*length*/2;
// used by DDMA, subkernel program data (need to provide extra ID and destination)
pub const MASTER_PAYLOAD_MAX_SIZE: usize = SAT_PAYLOAD_MAX_SIZE - /*source*/1 - /*destination*/1 - /*ID*/4;
// used by core device management, core_mgmt packet
// FIXME: packet size
pub const CORE_MGMT_PAYLOAD_MAX_SIZE: usize = MASTER_PAYLOAD_MAX_SIZE;
// pub const CORE_MGMT_CONFIG_MAX_SIZE: usize = /*max size*/MAX_PACKET - /*destination*/1 - /*last*/1 - /*length*/2;
pub const CORE_MGMT_CONFIG_MAX_SIZE: usize = MASTER_PAYLOAD_MAX_SIZE;
#[derive(Debug)]
pub enum Error {
@ -311,7 +306,7 @@ pub enum Packet {
CoreMgmtConfigReadRequest {
destination: u8,
length: u16,
key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE],
key: [u8; MASTER_PAYLOAD_MAX_SIZE],
},
CoreMgmtConfigReadContinue {
destination: u8,
@ -320,12 +315,12 @@ pub enum Packet {
destination: u8,
length: u16,
last: bool,
data: [u8; CORE_MGMT_CONFIG_MAX_SIZE],
data: [u8; MASTER_PAYLOAD_MAX_SIZE],
},
CoreMgmtConfigRemoveRequest {
destination: u8,
length: u16,
key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE],
key: [u8; MASTER_PAYLOAD_MAX_SIZE],
},
CoreMgmtConfigEraseRequest {
destination: u8,
@ -339,12 +334,12 @@ pub enum Packet {
CoreMgmtGetLogReply {
last: bool,
length: u16,
data: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE],
data: [u8; SAT_PAYLOAD_MAX_SIZE],
},
CoreMgmtConfigReadReply {
length: u16,
last: bool,
value: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE],
value: [u8; SAT_PAYLOAD_MAX_SIZE],
},
CoreMgmtAck,
CoreMgmtNack,
@ -642,7 +637,7 @@ impl Packet {
0xd4 => {
let destination = reader.read_u8()?;
let length = reader.read_u16()?;
let mut key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
let mut key: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE];
reader.read_exact(&mut key[0..length as usize])?;
Packet::CoreMgmtConfigReadRequest {
destination: destination,
@ -657,7 +652,7 @@ impl Packet {
let destination = reader.read_u8()?;
let length = reader.read_u16()?;
let last = reader.read_bool()?;
let mut data: [u8; CORE_MGMT_CONFIG_MAX_SIZE] = [0; CORE_MGMT_CONFIG_MAX_SIZE];
let mut data: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE];
reader.read_exact(&mut data[0..length as usize])?;
Packet::CoreMgmtConfigWriteRequest {
destination: destination,
@ -669,7 +664,7 @@ impl Packet {
0xd7 => {
let destination = reader.read_u8()?;
let length = reader.read_u16()?;
let mut key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
let mut key: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE];
reader.read_exact(&mut key[0..length as usize])?;
Packet::CoreMgmtConfigRemoveRequest {
destination: destination,
@ -689,7 +684,7 @@ impl Packet {
0xdb => {
let last = reader.read_bool()?;
let length = reader.read_u16()?;
let mut data: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
let mut data: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE];
reader.read_exact(&mut data[0..length as usize])?;
Packet::CoreMgmtGetLogReply {
last: last,
@ -700,7 +695,7 @@ impl Packet {
0xdc => {
let length = reader.read_u16()?;
let last = reader.read_bool()?;
let mut value: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
let mut value: [u8; SAT_PAYLOAD_MAX_SIZE] = [0; SAT_PAYLOAD_MAX_SIZE];
reader.read_exact(&mut value[0..length as usize])?;
Packet::CoreMgmtConfigReadReply {
length: length,

View File

@ -139,7 +139,7 @@ async fn read_key(stream: &mut TcpStream) -> Result<String> {
#[cfg(has_drtio)]
mod remote_coremgmt {
use io::{Cursor, ProtoWrite};
use libboard_artiq::drtioaux_proto::{Packet, CORE_MGMT_PAYLOAD_MAX_SIZE};
use libboard_artiq::drtioaux_proto::{MASTER_PAYLOAD_MAX_SIZE, Packet};
use super::*;
use crate::rtio_mgt::drtio;
@ -331,7 +331,7 @@ mod remote_coremgmt {
_cfg: &Rc<Config>,
key: &String,
) -> Result<()> {
let mut config_key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
let mut config_key: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE];
let len = key.len();
config_key[..len].clone_from_slice(key.as_bytes());
@ -442,7 +442,7 @@ mod remote_coremgmt {
_cfg: &Rc<Config>,
key: &String,
) -> Result<()> {
let mut config_key: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
let mut config_key: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE];
let len = key.len();
config_key[..len].clone_from_slice(key.as_bytes());

View File

@ -36,7 +36,7 @@ use libboard_artiq::si5324;
#[cfg(has_si549)]
use libboard_artiq::si549;
use libboard_artiq::{drtio_routing, drtioaux,
drtioaux_proto::{CORE_MGMT_PAYLOAD_MAX_SIZE, MASTER_PAYLOAD_MAX_SIZE, SAT_PAYLOAD_MAX_SIZE},
drtioaux_proto::{MASTER_PAYLOAD_MAX_SIZE, SAT_PAYLOAD_MAX_SIZE},
identifier_read, logger,
pl::csr};
#[cfg(feature = "target_kasli_soc")]
@ -1030,7 +1030,7 @@ fn process_aux_packet(
&packet,
timer
);
let mut data_slice: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
let mut data_slice = [0; SAT_PAYLOAD_MAX_SIZE];
let meta = core_manager.log_get_slice(&mut data_slice);
if clear && meta.status.is_first() {
mgmt::clear_log();
@ -1127,7 +1127,7 @@ fn process_aux_packet(
timer
);
let mut value_slice = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
let mut value_slice = [0; SAT_PAYLOAD_MAX_SIZE];
let key_slice = &key[..length as usize];
if !key_slice.is_ascii() {
@ -1170,7 +1170,7 @@ fn process_aux_packet(
timer
);
let mut value_slice = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
let mut value_slice = [0; SAT_PAYLOAD_MAX_SIZE];
let meta = core_manager.get_config_value_slice(&mut value_slice);
drtioaux::send(
0,
@ -1234,8 +1234,11 @@ fn process_aux_packet(
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
} else {
let key = core::str::from_utf8(key_slice).unwrap();
let succeeded = core_manager.remove_config(key).is_ok();
if core_manager.remove_config(key).is_ok() {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtAck)
} else {
drtioaux::send(0, &drtioaux::Packet::CoreMgmtNack)
}
}
}
drtioaux::Packet::CoreMgmtConfigEraseRequest {

View File

@ -1,7 +1,7 @@
use alloc::vec::Vec;
use io::{Cursor, ProtoRead, ProtoWrite};
use libboard_artiq::{drtioaux_proto::CORE_MGMT_PAYLOAD_MAX_SIZE,
use libboard_artiq::{drtioaux_proto::SAT_PAYLOAD_MAX_SIZE,
logger::{BufferLogger, LogBufferRef}};
use libconfig::Config;
use log::{self, debug, error, info, warn, LevelFilter};
@ -60,13 +60,13 @@ impl<'a> Manager<'_> {
}
}
pub fn log_get_slice(&mut self, data_slice: &mut [u8; CORE_MGMT_PAYLOAD_MAX_SIZE]) -> SliceMeta {
pub fn log_get_slice(&mut self, data_slice: &mut [u8; SAT_PAYLOAD_MAX_SIZE]) -> SliceMeta {
// Populate buffer if depleted
if self.last_log.at_end() {
self.last_log.extend(get_logger_buffer().extract().as_bytes());
}
self.last_log.get_slice_core_mgmt(data_slice)
self.last_log.get_slice_satellite(data_slice)
}
pub fn fetch_config_value(&mut self, key: &str) -> Result<()> {
@ -79,8 +79,8 @@ impl<'a> Manager<'_> {
.map_err(|_| warn!("read error: no such key"))
}
pub fn get_config_value_slice(&mut self, data_slice: &mut [u8; CORE_MGMT_PAYLOAD_MAX_SIZE]) -> SliceMeta {
self.last_value.get_slice_core_mgmt(data_slice)
pub fn get_config_value_slice(&mut self, data_slice: &mut [u8; SAT_PAYLOAD_MAX_SIZE]) -> SliceMeta {
self.last_value.get_slice_satellite(data_slice)
}
pub fn add_data(&mut self, data: &[u8], data_len: usize) {

View File

@ -4,7 +4,7 @@ use core::cmp::min;
#[cfg(has_drtio_routing)]
use libboard_artiq::pl::csr;
use libboard_artiq::{drtio_routing, drtioaux,
drtioaux_proto::{PayloadStatus, CORE_MGMT_PAYLOAD_MAX_SIZE, MASTER_PAYLOAD_MAX_SIZE}};
drtioaux_proto::{PayloadStatus, SAT_PAYLOAD_MAX_SIZE, MASTER_PAYLOAD_MAX_SIZE}};
pub struct SliceMeta {
pub destination: u8,
@ -58,7 +58,7 @@ impl Sliceable {
}
get_slice_fn!(get_slice_master, MASTER_PAYLOAD_MAX_SIZE);
get_slice_fn!(get_slice_core_mgmt, CORE_MGMT_PAYLOAD_MAX_SIZE);
get_slice_fn!(get_slice_satellite, SAT_PAYLOAD_MAX_SIZE);
}
// Packets from downstream (further satellites) are received and routed appropriately.