Commit 1d59a9a4 authored by Martin Kröning's avatar Martin Kröning 🦀
Browse files

Implement sys_free_tx_buffer

parent 8966c60a
......@@ -26,8 +26,12 @@ pub trait NetworkInterface {
/// Returns the current MTU of the device.
fn get_mtu(&self) -> u16;
/// Get buffer to create a TX packet
///
/// This returns ownership of the TX buffer.
fn get_tx_buffer(&mut self, len: usize) -> Result<(*mut u8, usize), ()>;
/// Send TC packets
/// Frees the TX buffer (takes ownership)
fn free_tx_buffer(&self, token: usize);
/// Send TC packets (takes TX buffer ownership)
fn send_tx_buffer(&mut self, tkn_handle: usize, len: usize) -> Result<(), ()>;
/// Check if a packet is available
fn has_packet(&self) -> bool;
......
......@@ -241,6 +241,10 @@ impl NetworkInterface for RTL8139Driver {
}
}
fn free_tx_buffer(&self, _token: usize) {
// get_tx_buffer did not allocate
}
fn send_tx_buffer(&mut self, id: usize, len: usize) -> Result<(), ()> {
// send the packet
unsafe {
......
......@@ -543,6 +543,10 @@ impl NetworkInterface for VirtioNetDriver {
}
}
fn free_tx_buffer(&self, token: usize) {
unsafe { drop(Box::from_raw(token as *mut BufferToken)) }
}
fn send_tx_buffer(&mut self, tkn_handle: usize, _len: usize) -> Result<(), ()> {
// This does not result in a new assignment, or in a drop of the BufferToken, which
// would be dangerous, as the memory is freed then.
......
......@@ -154,6 +154,19 @@ pub trait SyscallInterface: Send + Sync {
Err(())
}
fn free_tx_buffer(&self, handle: usize) -> Result<(), ()> {
#[cfg(all(feature = "pci", not(target_arch = "aarch64")))]
match arch::kernel::pci::get_network_driver() {
Some(driver) => {
driver.lock().free_tx_buffer(handle);
Ok(())
}
_ => Err(()),
}
#[cfg(not(all(feature = "pci", not(target_arch = "aarch64"))))]
Err(())
}
fn send_tx_buffer(&self, handle: usize, len: usize) -> Result<(), ()> {
#[cfg(all(feature = "pci", not(target_arch = "aarch64")))]
match arch::kernel::pci::get_network_driver() {
......
......@@ -114,6 +114,16 @@ extern "C" fn __sys_get_tx_buffer(len: usize, ret: &mut Result<(*mut u8, usize),
*ret = unsafe { SYS.get_tx_buffer(len) };
}
#[allow(improper_ctypes_definitions)]
extern "C" fn __sys_free_tx_buffer(handle: usize) -> Result<(), ()> {
unsafe { SYS.free_tx_buffer(handle) }
}
#[no_mangle]
pub fn sys_free_tx_buffer(handle: usize) -> Result<(), ()> {
kernel_function!(__sys_free_tx_buffer(handle))
}
#[no_mangle]
pub fn sys_get_tx_buffer(len: usize) -> Result<(*mut u8, usize), ()> {
let mut ret = Err(());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment