From a80a2c67ef26425732d1404c9209947d640bb85a Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 18 Jun 2020 01:25:43 +0200 Subject: [PATCH] eth: put desc list behind UncachedSlice, invalidate buffers, add barriers --- libboard_zynq/src/eth/mod.rs | 2 +- libboard_zynq/src/eth/rx.rs | 12 +++++++++--- libboard_zynq/src/eth/tx.rs | 8 +++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/libboard_zynq/src/eth/mod.rs b/libboard_zynq/src/eth/mod.rs index 3dbb2d3..413dd3b 100644 --- a/libboard_zynq/src/eth/mod.rs +++ b/libboard_zynq/src/eth/mod.rs @@ -20,7 +20,7 @@ const TX_100: u32 = 25_000_000; const TX_1000: u32 = 125_000_000; #[derive(Clone)] -#[repr(C, align(0x08))] +#[repr(C, align(0x20))] pub struct Buffer(pub [u8; MTU]); impl Buffer { diff --git a/libboard_zynq/src/eth/rx.rs b/libboard_zynq/src/eth/rx.rs index cc0847f..2af040d 100644 --- a/libboard_zynq/src/eth/rx.rs +++ b/libboard_zynq/src/eth/rx.rs @@ -1,5 +1,6 @@ use core::ops::Deref; use alloc::{vec, vec::Vec}; +use libcortex_a9::{asm::*, cache::*, UncachedSlice}; use libregister::*; use super::Buffer; @@ -55,15 +56,15 @@ register_bit!(desc_word1, global_broadcast, 31); #[repr(C)] pub struct DescList { - list: Vec, + list: UncachedSlice, buffers: Vec, next: usize, } impl DescList { pub fn new(size: usize) -> Self { - let mut list: Vec<_> = (0..size).map(|_| DescEntry::zeroed()) - .collect(); + let mut list = UncachedSlice::new(size, || DescEntry::zeroed()) + .unwrap(); let mut buffers = vec![Buffer::new(); size]; let last = list.len().min(buffers.len()) - 1; @@ -80,6 +81,7 @@ impl DescList { entry.word1.write( DescWord1::zeroed() ); + dcci_slice(&buffer[..]); } DescList { @@ -96,6 +98,7 @@ impl DescList { pub fn recv_next<'s: 'p, 'p>(&'s mut self) -> Result>, Error> { let list_len = self.list.len(); let entry = &mut self.list[self.next]; + dmb(); if entry.word0.read().used() { let word1 = entry.word1.read(); let len = word1.frame_length_lsbs().into(); @@ -126,7 +129,10 @@ pub struct PktRef<'a> { impl<'a> Drop for PktRef<'a> { fn drop(&mut self) { + dcci_slice(self.buffer); + self.entry.word0.modify(|_, w| w.used(false)); + dmb(); } } diff --git a/libboard_zynq/src/eth/tx.rs b/libboard_zynq/src/eth/tx.rs index 6261b3b..c4acf7d 100644 --- a/libboard_zynq/src/eth/tx.rs +++ b/libboard_zynq/src/eth/tx.rs @@ -1,5 +1,6 @@ use core::ops::{Deref, DerefMut}; use alloc::{vec, vec::Vec}; +use libcortex_a9::{cache::dcc_slice, UncachedSlice}; use libregister::*; use super::{Buffer, regs}; @@ -42,15 +43,15 @@ pub const DESCS: usize = 8; #[repr(C)] pub struct DescList { - list: Vec, + list: UncachedSlice, buffers: Vec, next: usize, } impl DescList { pub fn new(size: usize) -> Self { - let mut list: Vec<_> = (0..size).map(|_| DescEntry::zeroed()) - .collect(); + let mut list = UncachedSlice::new(size, || DescEntry::zeroed()) + .unwrap(); let mut buffers = vec![Buffer::new(); size]; let last = list.len().min(buffers.len()) - 1; @@ -123,6 +124,7 @@ pub struct PktRef<'a> { impl<'a> Drop for PktRef<'a> { fn drop(&mut self) { + dcc_slice(self.buffer); self.entry.word1.modify(|_, w| w.used(false)); if ! self.regs.tx_status.read().tx_go() { self.regs.net_ctrl.modify(|_, w|