|
|
@ -73,20 +73,19 @@ const E1000_RAH: usize = 0x5404 / 4;
|
|
|
|
pub struct E1000Interface {
|
|
|
|
pub struct E1000Interface {
|
|
|
|
iface: Mutex<EthernetInterface<'static, 'static, 'static, E1000Driver>>,
|
|
|
|
iface: Mutex<EthernetInterface<'static, 'static, 'static, E1000Driver>>,
|
|
|
|
driver: E1000Driver,
|
|
|
|
driver: E1000Driver,
|
|
|
|
|
|
|
|
name: String,
|
|
|
|
|
|
|
|
irq: Option<u32>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Driver for E1000Interface {
|
|
|
|
impl Driver for E1000Interface {
|
|
|
|
fn try_handle_interrupt(&self, _irq: Option<u32>) -> bool {
|
|
|
|
fn try_handle_interrupt(&self, irq: Option<u32>) -> bool {
|
|
|
|
let irq = {
|
|
|
|
if irq.is_some() && self.irq.is_some() && irq != self.irq {
|
|
|
|
let driver = self.driver.0.lock();
|
|
|
|
// not ours, skip it
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let None = active_table().get_entry(driver.header) {
|
|
|
|
let data = {
|
|
|
|
let mut current_addr = driver.header;
|
|
|
|
let driver = self.driver.0.lock();
|
|
|
|
while current_addr < driver.header + driver.size {
|
|
|
|
|
|
|
|
active_table().map_if_not_exists(current_addr, current_addr);
|
|
|
|
|
|
|
|
current_addr = current_addr + PAGE_SIZE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let e1000 = unsafe {
|
|
|
|
let e1000 = unsafe {
|
|
|
|
slice::from_raw_parts_mut(driver.header as *mut Volatile<u32>, driver.size / 4)
|
|
|
|
slice::from_raw_parts_mut(driver.header as *mut Volatile<u32>, driver.size / 4)
|
|
|
@ -102,7 +101,7 @@ impl Driver for E1000Interface {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if irq {
|
|
|
|
if data {
|
|
|
|
let timestamp = Instant::from_millis(crate::trap::uptime_msec() as i64);
|
|
|
|
let timestamp = Instant::from_millis(crate::trap::uptime_msec() as i64);
|
|
|
|
let mut sockets = SOCKETS.lock();
|
|
|
|
let mut sockets = SOCKETS.lock();
|
|
|
|
match self.iface.lock().poll(&mut sockets, timestamp) {
|
|
|
|
match self.iface.lock().poll(&mut sockets, timestamp) {
|
|
|
@ -115,7 +114,7 @@ impl Driver for E1000Interface {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return irq;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn device_type(&self) -> DeviceType {
|
|
|
|
fn device_type(&self) -> DeviceType {
|
|
|
@ -131,7 +130,7 @@ impl Driver for E1000Interface {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn get_ifname(&self) -> String {
|
|
|
|
fn get_ifname(&self) -> String {
|
|
|
|
format!("e1000")
|
|
|
|
self.name.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn ipv4_address(&self) -> Option<Ipv4Address> {
|
|
|
|
fn ipv4_address(&self) -> Option<Ipv4Address> {
|
|
|
@ -185,14 +184,6 @@ impl<'a> phy::Device<'a> for E1000Driver {
|
|
|
|
fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
|
|
|
|
fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
|
|
|
|
let driver = self.0.lock();
|
|
|
|
let driver = self.0.lock();
|
|
|
|
|
|
|
|
|
|
|
|
if let None = active_table().get_entry(driver.header) {
|
|
|
|
|
|
|
|
let mut current_addr = driver.header;
|
|
|
|
|
|
|
|
while current_addr < driver.header + driver.size {
|
|
|
|
|
|
|
|
active_table().map_if_not_exists(current_addr, current_addr);
|
|
|
|
|
|
|
|
current_addr = current_addr + PAGE_SIZE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let e1000 = unsafe {
|
|
|
|
let e1000 = unsafe {
|
|
|
|
slice::from_raw_parts_mut(driver.header as *mut Volatile<u32>, driver.size / 4)
|
|
|
|
slice::from_raw_parts_mut(driver.header as *mut Volatile<u32>, driver.size / 4)
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -238,14 +229,6 @@ impl<'a> phy::Device<'a> for E1000Driver {
|
|
|
|
fn transmit(&'a mut self) -> Option<Self::TxToken> {
|
|
|
|
fn transmit(&'a mut self) -> Option<Self::TxToken> {
|
|
|
|
let driver = self.0.lock();
|
|
|
|
let driver = self.0.lock();
|
|
|
|
|
|
|
|
|
|
|
|
if let None = active_table().get_entry(driver.header) {
|
|
|
|
|
|
|
|
let mut current_addr = driver.header;
|
|
|
|
|
|
|
|
while current_addr < driver.header + driver.size {
|
|
|
|
|
|
|
|
active_table().map_if_not_exists(current_addr, current_addr);
|
|
|
|
|
|
|
|
current_addr = current_addr + PAGE_SIZE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let e1000 = unsafe {
|
|
|
|
let e1000 = unsafe {
|
|
|
|
slice::from_raw_parts_mut(driver.header as *mut Volatile<u32>, driver.size / 4)
|
|
|
|
slice::from_raw_parts_mut(driver.header as *mut Volatile<u32>, driver.size / 4)
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -354,8 +337,8 @@ bitflags! {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// JudgeDuck-OS/kern/e1000.c
|
|
|
|
// JudgeDuck-OS/kern/e1000.c
|
|
|
|
pub fn e1000_init(header: usize, size: usize) {
|
|
|
|
pub fn e1000_init(name: String, irq: Option<u32>, header: usize, size: usize) {
|
|
|
|
info!("Probing e1000");
|
|
|
|
info!("Probing e1000 {}", name);
|
|
|
|
assert_eq!(size_of::<E1000SendDesc>(), 16);
|
|
|
|
assert_eq!(size_of::<E1000SendDesc>(), 16);
|
|
|
|
assert_eq!(size_of::<E1000RecvDesc>(), 16);
|
|
|
|
assert_eq!(size_of::<E1000RecvDesc>(), 16);
|
|
|
|
|
|
|
|
|
|
|
@ -387,12 +370,6 @@ pub fn e1000_init(header: usize, size: usize) {
|
|
|
|
first_trans: true,
|
|
|
|
first_trans: true,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let mut current_addr = header;
|
|
|
|
|
|
|
|
while current_addr < header + size {
|
|
|
|
|
|
|
|
active_table().map_if_not_exists(current_addr, current_addr);
|
|
|
|
|
|
|
|
current_addr = current_addr + PAGE_SIZE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let e1000 = unsafe { slice::from_raw_parts_mut(header as *mut Volatile<u32>, size / 4) };
|
|
|
|
let e1000 = unsafe { slice::from_raw_parts_mut(header as *mut Volatile<u32>, size / 4) };
|
|
|
|
debug!(
|
|
|
|
debug!(
|
|
|
|
"status before setup: {:#?}",
|
|
|
|
"status before setup: {:#?}",
|
|
|
@ -502,6 +479,8 @@ pub fn e1000_init(header: usize, size: usize) {
|
|
|
|
let e1000_iface = E1000Interface {
|
|
|
|
let e1000_iface = E1000Interface {
|
|
|
|
iface: Mutex::new(iface),
|
|
|
|
iface: Mutex::new(iface),
|
|
|
|
driver: net_driver.clone(),
|
|
|
|
driver: net_driver.clone(),
|
|
|
|
|
|
|
|
name,
|
|
|
|
|
|
|
|
irq,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let driver = Arc::new(e1000_iface);
|
|
|
|
let driver = Arc::new(e1000_iface);
|
|
|
|