From acebc3d691fdf7b5aacf32f5002152b3a58f29ae Mon Sep 17 00:00:00 2001 From: mwojcik Date: Fri, 19 Apr 2024 17:21:10 +0800 Subject: [PATCH] satellite: send async packets directly --- artiq/firmware/satman/main.rs | 16 ++------------ artiq/firmware/satman/repeater.rs | 36 +++++-------------------------- artiq/firmware/satman/routing.rs | 15 ------------- 3 files changed, 7 insertions(+), 60 deletions(-) diff --git a/artiq/firmware/satman/main.rs b/artiq/firmware/satman/main.rs index 1b9a4c53f..ed1cd238c 100644 --- a/artiq/firmware/satman/main.rs +++ b/artiq/firmware/satman/main.rs @@ -66,12 +66,6 @@ fn drtiosat_tsc_loaded() -> bool { } } -fn drtiosat_async_ready() { - unsafe { - csr::drtiosat::async_messages_ready_write(1); - } -} - #[derive(Clone, Copy)] pub enum RtioMaster { Drtio, @@ -252,12 +246,6 @@ fn process_aux_packet(dmamgr: &mut DmaManager, analyzer: &mut Analyzer, kernelmg drtioaux::send(0, &drtioaux::Packet::RoutingAck) } - drtioaux::Packet::RoutingRetrievePackets => { - let packet = router.get_upstream_packet().or( - Some(drtioaux::Packet::RoutingNoPackets)).unwrap(); - drtioaux::send(0, &packet) - } - drtioaux::Packet::MonitorRequest { destination: _destination, channel, probe } => { forward!(_routing_table, _destination, *rank, _repeaters, &packet); let value; @@ -808,8 +796,8 @@ pub extern fn main() -> i32 { } } - if router.any_upstream_waiting() { - drtiosat_async_ready(); + if let Some(packet) = router.get_upstream_packet() { + drtioaux::send(0, &packet).unwrap(); } } diff --git a/artiq/firmware/satman/repeater.rs b/artiq/firmware/satman/repeater.rs index 544527cda..cd18badc2 100644 --- a/artiq/firmware/satman/repeater.rs +++ b/artiq/firmware/satman/repeater.rs @@ -49,7 +49,7 @@ impl Repeater { self.state == RepeaterState::Up } - pub fn service(&mut self, routing_table: &drtio_routing::RoutingTable, rank: u8, destination: u8, router: &mut Router) { + pub fn service(&mut self, routing_table: &drtio_routing::RoutingTable, rank: u8, self_destination: u8, router: &mut Router) { self.process_local_errors(); match self.state { @@ -107,16 +107,11 @@ impl Repeater { } } RepeaterState::Up => { - self.process_unsolicited_aux(); + self.process_unsolicited_aux(routing_table, rank, self_destination, router); if !rep_link_rx_up(self.repno) { info!("[REP#{}] link is down", self.repno); self.state = RepeaterState::Down; } - if self.async_messages_ready() { - if let Err(e) = self.handle_async(routing_table, rank, destination, router) { - warn!("[REP#{}] Error handling async messages ({})", self.repno, e); - } - } } RepeaterState::Failed => { if !rep_link_rx_up(self.repno) { @@ -127,9 +122,10 @@ impl Repeater { } } - fn process_unsolicited_aux(&self) { + fn process_unsolicited_aux(&self, routing_table: &drtio_routing::RoutingTable, + rank: u8, self_destination: u8, router: &mut Router) { match drtioaux::recv(self.auxno) { - Ok(Some(packet)) => warn!("[REP#{}] unsolicited aux packet: {:?}", self.repno, packet), + Ok(Some(packet)) => router.route(packet, routing_table, rank, self_destination), Ok(None) => (), Err(_) => warn!("[REP#{}] aux packet error", self.repno) } @@ -185,28 +181,6 @@ impl Repeater { } } - fn async_messages_ready(&self) -> bool { - let async_rdy; - unsafe { - async_rdy = (csr::DRTIOREP[self.repno as usize].async_messages_ready_read)(); - (csr::DRTIOREP[self.repno as usize].async_messages_ready_write)(0); - } - async_rdy == 1 - } - - fn handle_async(&self, routing_table: &drtio_routing::RoutingTable, rank: u8, self_destination: u8, router: &mut Router - ) -> Result<(), drtioaux::Error> { - loop { - drtioaux::send(self.auxno, &drtioaux::Packet::RoutingRetrievePackets).unwrap(); - let reply = self.recv_aux_timeout(200)?; - match reply { - drtioaux::Packet::RoutingNoPackets => break, - packet => router.route(packet, routing_table, rank, self_destination) - } - } - Ok(()) - } - pub fn aux_forward(&self, request: &drtioaux::Packet) -> Result<(), drtioaux::Error> { self.aux_send(request)?; let reply = self.recv_aux_timeout(200)?; diff --git a/artiq/firmware/satman/routing.rs b/artiq/firmware/satman/routing.rs index 169630dbd..cb17d6822 100644 --- a/artiq/firmware/satman/routing.rs +++ b/artiq/firmware/satman/routing.rs @@ -75,7 +75,6 @@ pub struct Router { local_queue: VecDeque, #[cfg(has_drtio_routing)] downstream_queue: VecDeque<(usize, drtioaux::Packet)>, - upstream_notified: bool, } impl Router { @@ -85,7 +84,6 @@ impl Router { local_queue: VecDeque::new(), #[cfg(has_drtio_routing)] downstream_queue: VecDeque::new(), - upstream_notified: false, } } @@ -155,21 +153,8 @@ impl Router { } } - pub fn any_upstream_waiting(&mut self) -> bool { - let empty = self.upstream_queue.is_empty(); - if !empty && !self.upstream_notified { - self.upstream_notified = true; // so upstream will not get spammed with notifications - true - } else { - false - } - } - pub fn get_upstream_packet(&mut self) -> Option { let packet = self.upstream_queue.pop_front(); - if packet.is_none() { - self.upstream_notified = false; - } packet }