From de6beb89929ae2b032121c8d3d30f5e41bf0f5e7 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:48:02 +0100 Subject: [PATCH] Implement network:mac in all remaining network drivers --- ixgbed/src/device.rs | 10 +++++++--- rtl8139d/src/device.rs | 6 ++++-- rtl8168d/src/device.rs | 6 ++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ixgbed/src/device.rs b/ixgbed/src/device.rs index 3fd47e029b..690dfb1be0 100644 --- a/ixgbed/src/device.rs +++ b/ixgbed/src/device.rs @@ -21,6 +21,7 @@ pub struct Intel8259x { transmit_ring_free: usize, transmit_index: usize, transmit_clean_index: usize, + mac_address: [u8; 6], } fn wrap_ring(index: usize, ring_size: usize) -> usize { @@ -29,8 +30,7 @@ fn wrap_ring(index: usize, ring_size: usize) -> usize { impl NetworkAdapter for Intel8259x { fn mac_address(&mut self) -> [u8; 6] { - // FIXME read from the network adapter itself - [0xfe; 6] // FE-FE-FE-FE-FE-FE + self.mac_address } fn available_for_read(&mut self) -> usize { @@ -145,6 +145,7 @@ impl Intel8259x { transmit_ring_free: 32, transmit_index: 0, transmit_clean_index: 0, + mac_address: [0; 6], }; module.init(); @@ -192,7 +193,7 @@ impl Intel8259x { /// Sets the mac address of this device. #[allow(dead_code)] - pub fn set_mac_addr(&self, mac: [u8; 6]) { + pub fn set_mac_addr(&mut self, mac: [u8; 6]) { let low: u32 = u32::from(mac[0]) + (u32::from(mac[1]) << 8) + (u32::from(mac[2]) << 16) @@ -201,6 +202,8 @@ impl Intel8259x { self.write_reg(IXGBE_RAL(0), low); self.write_reg(IXGBE_RAH(0), high); + + self.mac_address = mac; } /// Returns the register at `self.base` + `register`. @@ -289,6 +292,7 @@ impl Intel8259x { mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] ), ); + self.mac_address = mac; // section 4.6.3 - wait for EEPROM auto read completion self.wait_write_reg(IXGBE_EEC, IXGBE_EEC_ARD); diff --git a/rtl8139d/src/device.rs b/rtl8139d/src/device.rs index fd64fd294f..746ecd5646 100644 --- a/rtl8139d/src/device.rs +++ b/rtl8139d/src/device.rs @@ -124,12 +124,12 @@ pub struct Rtl8139 { receive_i: usize, transmit_buffer: [Dma<[Mmio; 1792]>; 4], transmit_i: usize, + mac_address: [u8; 6], } impl NetworkAdapter for Rtl8139 { fn mac_address(&mut self) -> [u8; 6] { - // FIXME read from the network adapter itself - [0xfe; 6] // FE-FE-FE-FE-FE-FE + self.mac_address } fn available_for_read(&mut self) -> usize { @@ -221,6 +221,7 @@ impl Rtl8139 { .try_into() .unwrap_or_else(|_| unreachable!()), transmit_i: 0, + mac_address: [0; 6], }; module.init(); @@ -272,6 +273,7 @@ impl Rtl8139 { (mac_high >> 8) as u8]; println!(" - MAC: {:>02X}:{:>02X}:{:>02X}:{:>02X}:{:>02X}:{:>02X}", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); let _ = setcfg("mac", &format!("{:>02X}-{:>02X}-{:>02X}-{:>02X}-{:>02X}-{:>02X}\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5])); + self.mac_address = mac; // Reset - this will disable tx and rx, reinitialize FIFOs, and set the system buffer pointer to the initial value println!(" - Reset"); diff --git a/rtl8168d/src/device.rs b/rtl8168d/src/device.rs index eaff7ea829..5dd76a8504 100644 --- a/rtl8168d/src/device.rs +++ b/rtl8168d/src/device.rs @@ -78,12 +78,12 @@ pub struct Rtl8168 { transmit_i: usize, transmit_buffer_h: [Dma<[Mmio; 7552]>; 1], transmit_ring_h: Dma<[Td; 1]>, + mac_address: [u8; 6], } impl NetworkAdapter for Rtl8168 { fn mac_address(&mut self) -> [u8; 6] { - // FIXME read from the network adapter itself - [0xfe; 6] // FE-FE-FE-FE-FE-FE + self.mac_address } fn available_for_read(&mut self) -> usize { @@ -192,6 +192,7 @@ impl Rtl8168 { transmit_i: 0, transmit_buffer_h: [Dma::zeroed()?.assume_init()], transmit_ring_h: Dma::zeroed()?.assume_init(), + mac_address: [0; 6], }; module.init(); @@ -232,6 +233,7 @@ impl Rtl8168 { (mac_high >> 8) as u8]; println!(" - MAC: {:>02X}:{:>02X}:{:>02X}:{:>02X}:{:>02X}:{:>02X}", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); let _ = setcfg("mac", &format!("{:>02X}-{:>02X}-{:>02X}-{:>02X}-{:>02X}-{:>02X}\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5])); + self.mac_address = mac; // Reset - this will disable tx and rx, reinitialize FIFOs, and set the system buffer pointer to the initial value println!(" - Reset");