Map ixgbe to kernel space as well

master
Jiajie Chen 6 years ago
parent ee66451873
commit b4bd960a74

@ -125,10 +125,15 @@ pub fn init_driver(dev: &PCIDevice) {
// 82599ES 10-Gigabit SFI/SFP+ Network Connection // 82599ES 10-Gigabit SFI/SFP+ Network Connection
if let Some(BAR::Memory(addr, len, _, _)) = dev.bars[0] { if let Some(BAR::Memory(addr, len, _, _)) = dev.bars[0] {
let irq = unsafe { enable(dev.loc) }; let irq = unsafe { enable(dev.loc) };
PCI_DRIVERS.lock().insert( let vaddr = KERNEL_OFFSET + addr as usize;
dev.loc, let mut current_addr = addr as usize;
ixgbe::ixgbe_init(name, irq, addr as usize, len as usize), while current_addr < addr as usize + len as usize {
); active_table().map_if_not_exists(KERNEL_OFFSET + current_addr, current_addr);
current_addr = current_addr + PAGE_SIZE;
}
PCI_DRIVERS
.lock()
.insert(dev.loc, ixgbe::ixgbe_init(name, irq, vaddr, len as usize));
} }
} }
(0x8086, 0x2922) => { (0x8086, 0x2922) => {

@ -32,21 +32,6 @@ struct IXGBEDriver {
mtu: usize, mtu: usize,
} }
impl Drop for IXGBEDriver {
fn drop(&mut self) {
let _ = FlagsGuard::no_irq_region();
let header = self.header;
let size = self.size;
if let None = active_table().get_entry(header) {
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;
}
}
}
}
pub struct IXGBEInterface { pub struct IXGBEInterface {
iface: Mutex<EthernetInterface<'static, 'static, 'static, IXGBEDriver>>, iface: Mutex<EthernetInterface<'static, 'static, 'static, IXGBEDriver>>,
driver: IXGBEDriver, driver: IXGBEDriver,
@ -64,16 +49,6 @@ impl Driver for IXGBEInterface {
let handled = { let handled = {
let _ = FlagsGuard::no_irq_region(); let _ = FlagsGuard::no_irq_region();
let header = self.driver.header;
let size = self.driver.size;
if let None = active_table().get_entry(header) {
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;
}
}
self.driver.inner.try_handle_interrupt() self.driver.inner.try_handle_interrupt()
}; };
@ -135,15 +110,6 @@ impl<'a> phy::Device<'a> for IXGBEDriver {
fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> { fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
let _ = FlagsGuard::no_irq_region(); let _ = FlagsGuard::no_irq_region();
let header = self.header;
let size = self.size;
if let None = active_table().get_entry(header) {
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;
}
}
if self.inner.can_send() { if self.inner.can_send() {
if let Some(data) = self.inner.recv() { if let Some(data) = self.inner.recv() {
Some((IXGBERxToken(data), IXGBETxToken(self.clone()))) Some((IXGBERxToken(data), IXGBETxToken(self.clone())))
@ -157,15 +123,6 @@ impl<'a> phy::Device<'a> for IXGBEDriver {
fn transmit(&'a mut self) -> Option<Self::TxToken> { fn transmit(&'a mut self) -> Option<Self::TxToken> {
let _ = FlagsGuard::no_irq_region(); let _ = FlagsGuard::no_irq_region();
let header = self.header;
let size = self.size;
if let None = active_table().get_entry(header) {
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;
}
}
if self.inner.can_send() { if self.inner.can_send() {
Some(IXGBETxToken(self.clone())) Some(IXGBETxToken(self.clone()))
} else { } else {
@ -200,15 +157,6 @@ impl phy::TxToken for IXGBETxToken {
F: FnOnce(&mut [u8]) -> Result<R>, F: FnOnce(&mut [u8]) -> Result<R>,
{ {
let _ = FlagsGuard::no_irq_region(); let _ = FlagsGuard::no_irq_region();
let header = self.0.header;
let size = self.0.size;
if let None = active_table().get_entry(header) {
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 mut buffer = [0u8; ixgbe::IXGBEDriver::get_mtu()]; let mut buffer = [0u8; ixgbe::IXGBEDriver::get_mtu()];
let result = f(&mut buffer[..len]); let result = f(&mut buffer[..len]);
if result.is_ok() { if result.is_ok() {
@ -225,13 +173,6 @@ pub fn ixgbe_init(
size: usize, size: usize,
) -> Arc<IXGBEInterface> { ) -> Arc<IXGBEInterface> {
let _ = FlagsGuard::no_irq_region(); let _ = FlagsGuard::no_irq_region();
if let None = active_table().get_entry(header) {
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 ixgbe = ixgbe::IXGBEDriver::init(Provider::new(), header, size); let ixgbe = ixgbe::IXGBEDriver::init(Provider::new(), header, size);
ixgbe.enable_irq(); ixgbe.enable_irq();

Loading…
Cancel
Save