forked from myrfy001/r4l-e1000
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathring_buf.rs
More file actions
57 lines (46 loc) · 1.42 KB
/
ring_buf.rs
File metadata and controls
57 lines (46 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use kernel::net::SkBuff;
use kernel::prelude::*;
use kernel::dma;
use core::cell::RefCell;
use crate::hw_defs::{RxDescEntry,TxDescEntry};
/// A pair made up of a SkBuff and it's dma mapping
pub(crate) type SkbDma = (dma::MapSingle::<u8>, ARef<SkBuff>);
/// A slice view into `dma::Allocation`.
pub(crate) struct DmaAllocSlice<T> {
desc: dma::Allocation::<T>,
count: usize,
}
impl<T> DmaAllocSlice<T> {
pub(crate) fn as_desc_slice(&mut self) -> &mut [T] {
unsafe{core::slice::from_raw_parts_mut(self.desc.cpu_addr, self.count)}
}
pub(crate) fn get_dma_addr(&self) -> usize {
self.desc.dma_handle as usize
}
pub(crate) fn get_cpu_addr(&self) -> usize {
self.desc.cpu_addr as usize
}
}
pub(crate) struct RingBuf<T> {
pub(crate) desc: DmaAllocSlice<T>,
pub(crate) buf: RefCell<Vec<Option<SkbDma>>>,
pub(crate) next_to_clean: usize,
}
impl<T> RingBuf<T> {
pub(crate) fn new(desc: dma::Allocation::<T>, len: usize) -> Self {
let buf = RefCell::new(Vec::new());
{
let mut buf_ref = buf.borrow_mut();
for _ in 0..len{
buf_ref.try_push(None).unwrap();
}
}
let desc = DmaAllocSlice{
desc,
count: len,
};
Self {desc, buf, next_to_clean:0}
}
}
pub(crate) type RxRingBuf = RingBuf<RxDescEntry>;
pub(crate) type TxRingBuf = RingBuf<TxDescEntry>;