Skip to content
Open
35 changes: 27 additions & 8 deletions awkernel_drivers/src/ic/genet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use awkernel_lib::{
ether::{ETHER_ADDR_LEN, ETHER_BROADCAST_ADDR},
multicast::MulticastAddrs,
net_device::{
self, EtherFrameBuf, EtherFrameRef, LinkStatus, NetCapabilities, NetDevError,
NetDevice, NetFlags,
self, EtherFrameBuf, LinkStatus, NetCapabilities, NetDevError, NetDevice, NetFlags,
PacketHeaderFlags,
},
},
paging::PAGESIZE,
Expand Down Expand Up @@ -335,7 +335,7 @@ impl NetDevice for Genet {
Ok(())
}

fn send(&self, data: EtherFrameRef, _que_id: usize) -> Result<(), NetDevError> {
fn send(&self, data: EtherFrameBuf, _que_id: usize) -> Result<(), NetDevError> {
let inner = self.inner.read();
let frames = [data];
inner.send(&frames);
Expand Down Expand Up @@ -746,7 +746,7 @@ impl GenetInner {
registers::TBUF_CTRL.write(buf_ctrl, base);
}

fn send(&self, ether_frames: &[EtherFrameRef]) {
fn send(&self, ether_frames: &[EtherFrameBuf]) {
if !self.if_flags.contains(NetFlags::RUNNING | NetFlags::UP) {
return;
}
Expand Down Expand Up @@ -776,7 +776,7 @@ impl GenetInner {
break;
}

let size = frame.data.len();
let size = frame.data.get_size();

let mut length_status = registers::TX_DESC_STATUS_QTAG_MASK
| registers::TX_DESC_STATUS_SOP
Expand All @@ -786,7 +786,15 @@ impl GenetInner {
length_status |= (size as u32) << registers::TX_DESC_STATUS_BUFLEN_SHIFT;

let buf = tx.buf.as_mut().get_mut(index).unwrap();
unsafe { core::ptr::copy_nonoverlapping(frame.data.as_ptr(), buf.as_mut_ptr(), size) };

// TODO: This implementation has an unnecessary copy
unsafe {
core::ptr::copy_nonoverlapping(
frame.data.as_ref().as_ptr(),
buf.as_mut_ptr(),
buf.len(),
);
}

let addr = tx.buf.get_phy_addr() + index * TX_BUF_SIZE;
let addr = addr.as_usize();
Expand Down Expand Up @@ -1092,9 +1100,20 @@ impl GenetInner {
{
// error
} else if let Some(buf) = rx.buf.as_ref().get(index) {
let data = buf[2..len as usize].to_vec();
// TODO: This implementation has an unnecessary copy
let mut data = DMAPool::<[u8; PAGESIZE]>::new(0, 1).unwrap();
let dst_ptr = data.as_mut() as *mut u8;
unsafe {
let buf_ptr = buf.as_ptr().add(2);
core::ptr::copy_nonoverlapping(buf_ptr, dst_ptr, len as usize - 2);
}

let frame = EtherFrameBuf { data, vlan: None };
let frame = EtherFrameBuf {
data,
len: (len - 2) as usize,
vlan: None,
csum_flags: PacketHeaderFlags::empty(),
};
let _ = rx.read_queue.push(frame);
}

Expand Down
2 changes: 1 addition & 1 deletion awkernel_drivers/src/pcie/intel/e1000e_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl NetDevice for E1000eExample {

fn send(
&self,
_data: net_device::EtherFrameRef,
_data: net_device::EtherFrameBuf,
_que_id: usize,
) -> Result<(), net_device::NetDevError> {
todo!("send");
Expand Down
Loading
Loading