From ec5dda4d0a45dfc76166f474ccb4408cdb5874bc Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 22 Jun 2019 01:34:17 +0200 Subject: [PATCH] eth: add const MTU --- src/eth/mod.rs | 11 +++++++---- src/eth/rx.rs | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/eth/mod.rs b/src/eth/mod.rs index 17c2842..ddd7f49 100644 --- a/src/eth/mod.rs +++ b/src/eth/mod.rs @@ -6,6 +6,9 @@ mod regs; pub mod rx; pub mod tx; +/// Size of all the buffers +pub const MTU: usize = 1536; + pub struct Eth { regs: &'static mut regs::RegisterBlock, rx: RX, @@ -295,7 +298,7 @@ impl Eth { self.regs.dma_cfg.write( regs::DmaCfg::zeroed() // 1536 bytes - .ahb_mem_rx_buf_size(0x18) + .ahb_mem_rx_buf_size((MTU >> 6) as u8) // 8 KB .rx_pktbuf_memsz_sel(0x3) // 4 KB @@ -313,10 +316,10 @@ impl Eth { ); } - pub fn start_rx<'rx>(self, list: &'rx mut [rx::DescEntry], rx_buffers: &'rx mut [[u8; 1536]]) -> Eth, TX> { + pub fn start_rx<'rx>(self, rx_list: &'rx mut [rx::DescEntry], rx_buffers: &'rx mut [[u8; MTU]]) -> Eth, TX> { let new_self = Eth { regs: self.regs, - rx: rx::DescList::new(list, rx_buffers), + rx: rx::DescList::new(rx_list, rx_buffers), tx: self.tx, }; let list_addr = new_self.rx.list_addr(); @@ -355,7 +358,7 @@ impl Eth { } impl<'rx, TX> Eth, TX> { - pub fn recv_next(&mut self) -> Result, rx::Error> { + pub fn recv_next<'s: 'p, 'p>(&'s mut self) -> Result>, rx::Error> { let status = self.regs.rx_status.read(); if status.hresp_not_ok() { // Clear diff --git a/src/eth/rx.rs b/src/eth/rx.rs index 36586bb..516ea80 100644 --- a/src/eth/rx.rs +++ b/src/eth/rx.rs @@ -1,5 +1,6 @@ use core::ops::Deref; use crate::{register, register_bit, register_bits, register_bits_typed, regs::*}; +use super::MTU; #[derive(Debug)] pub enum Error { @@ -43,12 +44,12 @@ register_bit!(desc_word1, global_broadcast, 31); #[repr(C)] pub struct DescList<'a> { list: &'a mut [DescEntry], - buffers: &'a mut [[u8; 1536]], + buffers: &'a mut [[u8; MTU]], next: usize, } impl<'a> DescList<'a> { - pub fn new(list: &'a mut [DescEntry], buffers: &'a mut [[u8; 1536]]) -> Self { + pub fn new(list: &'a mut [DescEntry], buffers: &'a mut [[u8; MTU]]) -> Self { let last = list.len().min(buffers.len()) - 1; for (i, (entry, buffer)) in list.iter_mut().zip(buffers.iter_mut()).enumerate() { let is_last = i == last;