Implement network:mac in all remaining network drivers

This commit is contained in:
bjorn3
2024-02-26 20:48:02 +01:00
parent 3751c915fe
commit de6beb8992
3 changed files with 15 additions and 7 deletions
+7 -3
View File
@@ -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);
+4 -2
View File
@@ -124,12 +124,12 @@ pub struct Rtl8139 {
receive_i: usize,
transmit_buffer: [Dma<[Mmio<u8>; 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");
+4 -2
View File
@@ -78,12 +78,12 @@ pub struct Rtl8168 {
transmit_i: usize,
transmit_buffer_h: [Dma<[Mmio<u8>; 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");