diff --git a/src/eth/rx.rs b/src/eth/rx.rs index 309a0ba2..9022ff9f 100644 --- a/src/eth/rx.rs +++ b/src/eth/rx.rs @@ -69,7 +69,8 @@ impl<'a> DescList<'a> { } DescList { - list, + // Shorten the list of descriptors to the required number. + list: &mut list[0..=last], buffers, next: 0, } @@ -85,7 +86,7 @@ impl<'a> DescList<'a> { if entry.word0.read().used() { let word1 = entry.word1.read(); let len = word1.frame_length_lsbs().into(); - let buffer = &self.buffers[self.next][0..len]; + let buffer = &mut self.buffers[self.next][0..len]; self.next += 1; if self.next >= list_len { @@ -107,7 +108,7 @@ impl<'a> DescList<'a> { /// Releases a buffer back to the HW upon Drop pub struct PktRef<'a> { entry: &'a mut DescEntry, - buffer: &'a [u8], + buffer: &'a mut [u8], } impl<'a> Drop for PktRef<'a> { diff --git a/src/eth/tx.rs b/src/eth/tx.rs index 8852bfe8..4bf0185c 100644 --- a/src/eth/tx.rs +++ b/src/eth/tx.rs @@ -40,6 +40,12 @@ pub struct DescList<'a> { impl<'a> DescList<'a> { pub fn new(list: &'a mut [DescEntry], buffers: &'a mut [[u8; MTU]]) -> Self { let last = list.len().min(buffers.len()) - 1; + // Sending seems to not work properly with only one packet + // buffer (two duplicates get send with every packet), so + // check that at least 2 are allocated, i.e. that the index of + // the last one is at least one. + assert!(last > 0); + for (i, (entry, buffer)) in list.iter_mut().zip(buffers.iter_mut()).enumerate() { let is_last = i == last; let buffer_addr = &mut buffer[0] as *mut _ as u32; @@ -58,7 +64,8 @@ impl<'a> DescList<'a> { } DescList { - list, + // Shorten the list of descriptors to the required number. + list: &mut list[0..=last], buffers, next: 0, }