forked from M-Labs/zynq-rs
1
0
Fork 0

eth: put desc list behind UncachedSlice, invalidate buffers, add barriers

This commit is contained in:
Astro 2020-06-18 01:25:43 +02:00
parent d96343c249
commit a80a2c67ef
3 changed files with 15 additions and 7 deletions

View File

@ -20,7 +20,7 @@ const TX_100: u32 = 25_000_000;
const TX_1000: u32 = 125_000_000; const TX_1000: u32 = 125_000_000;
#[derive(Clone)] #[derive(Clone)]
#[repr(C, align(0x08))] #[repr(C, align(0x20))]
pub struct Buffer(pub [u8; MTU]); pub struct Buffer(pub [u8; MTU]);
impl Buffer { impl Buffer {

View File

@ -1,5 +1,6 @@
use core::ops::Deref; use core::ops::Deref;
use alloc::{vec, vec::Vec}; use alloc::{vec, vec::Vec};
use libcortex_a9::{asm::*, cache::*, UncachedSlice};
use libregister::*; use libregister::*;
use super::Buffer; use super::Buffer;
@ -55,15 +56,15 @@ register_bit!(desc_word1, global_broadcast, 31);
#[repr(C)] #[repr(C)]
pub struct DescList { pub struct DescList {
list: Vec<DescEntry>, list: UncachedSlice<DescEntry>,
buffers: Vec<Buffer>, buffers: Vec<Buffer>,
next: usize, next: usize,
} }
impl DescList { impl DescList {
pub fn new(size: usize) -> Self { pub fn new(size: usize) -> Self {
let mut list: Vec<_> = (0..size).map(|_| DescEntry::zeroed()) let mut list = UncachedSlice::new(size, || DescEntry::zeroed())
.collect(); .unwrap();
let mut buffers = vec![Buffer::new(); size]; let mut buffers = vec![Buffer::new(); size];
let last = list.len().min(buffers.len()) - 1; let last = list.len().min(buffers.len()) - 1;
@ -80,6 +81,7 @@ impl DescList {
entry.word1.write( entry.word1.write(
DescWord1::zeroed() DescWord1::zeroed()
); );
dcci_slice(&buffer[..]);
} }
DescList { DescList {
@ -96,6 +98,7 @@ impl DescList {
pub fn recv_next<'s: 'p, 'p>(&'s mut self) -> Result<Option<PktRef<'p>>, Error> { pub fn recv_next<'s: 'p, 'p>(&'s mut self) -> Result<Option<PktRef<'p>>, Error> {
let list_len = self.list.len(); let list_len = self.list.len();
let entry = &mut self.list[self.next]; let entry = &mut self.list[self.next];
dmb();
if entry.word0.read().used() { if entry.word0.read().used() {
let word1 = entry.word1.read(); let word1 = entry.word1.read();
let len = word1.frame_length_lsbs().into(); let len = word1.frame_length_lsbs().into();
@ -126,7 +129,10 @@ pub struct PktRef<'a> {
impl<'a> Drop for PktRef<'a> { impl<'a> Drop for PktRef<'a> {
fn drop(&mut self) { fn drop(&mut self) {
dcci_slice(self.buffer);
self.entry.word0.modify(|_, w| w.used(false)); self.entry.word0.modify(|_, w| w.used(false));
dmb();
} }
} }

View File

@ -1,5 +1,6 @@
use core::ops::{Deref, DerefMut}; use core::ops::{Deref, DerefMut};
use alloc::{vec, vec::Vec}; use alloc::{vec, vec::Vec};
use libcortex_a9::{cache::dcc_slice, UncachedSlice};
use libregister::*; use libregister::*;
use super::{Buffer, regs}; use super::{Buffer, regs};
@ -42,15 +43,15 @@ pub const DESCS: usize = 8;
#[repr(C)] #[repr(C)]
pub struct DescList { pub struct DescList {
list: Vec<DescEntry>, list: UncachedSlice<DescEntry>,
buffers: Vec<Buffer>, buffers: Vec<Buffer>,
next: usize, next: usize,
} }
impl DescList { impl DescList {
pub fn new(size: usize) -> Self { pub fn new(size: usize) -> Self {
let mut list: Vec<_> = (0..size).map(|_| DescEntry::zeroed()) let mut list = UncachedSlice::new(size, || DescEntry::zeroed())
.collect(); .unwrap();
let mut buffers = vec![Buffer::new(); size]; let mut buffers = vec![Buffer::new(); size];
let last = list.len().min(buffers.len()) - 1; let last = list.len().min(buffers.len()) - 1;
@ -123,6 +124,7 @@ pub struct PktRef<'a> {
impl<'a> Drop for PktRef<'a> { impl<'a> Drop for PktRef<'a> {
fn drop(&mut self) { fn drop(&mut self) {
dcc_slice(self.buffer);
self.entry.word1.modify(|_, w| w.used(false)); self.entry.word1.modify(|_, w| w.used(false));
if ! self.regs.tx_status.read().tx_go() { if ! self.regs.tx_status.read().tx_go() {
self.regs.net_ctrl.modify(|_, w| self.regs.net_ctrl.modify(|_, w|