From efbafce4cbef1f6c02670cf698480c29d8f5f27b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 1 May 2024 12:33:01 +0200 Subject: [PATCH 01/10] fix(gem-net): clippy::identity_op MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/drivers/net/gem.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/net/gem.rs b/src/drivers/net/gem.rs index b9ed56dde7..a363217b0a 100644 --- a/src/drivers/net/gem.rs +++ b/src/drivers/net/gem.rs @@ -507,8 +507,8 @@ pub fn init_device( let bottom: u32 = ((mac[3] as u32) << 24) + ((mac[2] as u32) << 16) + ((mac[1] as u32) << 8) - + ((mac[0] as u32) << 0); - let top: u32 = ((mac[5] as u32) << 8) + ((mac[4] as u32) << 0); + + (mac[0] as u32); + let top: u32 = ((mac[5] as u32) << 8) + (mac[4] as u32); (*gem).spec_add1_bottom.set(bottom); (*gem).spec_add1_top.set(top); From 6bca1c52a3ca8343361c70c02a23eed1530a37cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 1 May 2024 12:33:37 +0200 Subject: [PATCH 02/10] fix(gem-net): clippy::unnecessary_cast MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/drivers/net/gem.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/net/gem.rs b/src/drivers/net/gem.rs index a363217b0a..1eba968225 100644 --- a/src/drivers/net/gem.rs +++ b/src/drivers/net/gem.rs @@ -406,7 +406,7 @@ impl GEMDriver { debug!("rx_buffer_consumed: handle: {}", handle); let word0_addr = (self.rxbuffer_list + (handle * 8) as u64); - let word1_addr = word0_addr + 4 as u64; + let word1_addr = word0_addr + 4_u64; unsafe { // Clear word1 (is this really necessary?) From 6ab5317c812b483d53cb0f213b788461b303c653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 1 May 2024 12:34:09 +0200 Subject: [PATCH 03/10] fix(gem-net): clippy::redundant_pattern_matching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/drivers/net/gem.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/drivers/net/gem.rs b/src/drivers/net/gem.rs index 1eba968225..e007aade51 100644 --- a/src/drivers/net/gem.rs +++ b/src/drivers/net/gem.rs @@ -299,10 +299,7 @@ impl NetworkDriver for GEMDriver { fn has_packet(&self) -> bool { debug!("has_packet"); - match self.next_rx_index() { - Some(_) => true, - None => false, - } + self.next_rx_index().is_some() } fn receive_packet(&mut self) -> Option<(RxToken, TxToken)> { From 61a86175a7b91295ba9c7d244dfba1683c8ee583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 1 May 2024 12:37:53 +0200 Subject: [PATCH 04/10] fix(gem-net): clippy::useless_conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/arch/riscv64/kernel/devicetree.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arch/riscv64/kernel/devicetree.rs b/src/arch/riscv64/kernel/devicetree.rs index e83a5ed0c4..6968aa7ab2 100644 --- a/src/arch/riscv64/kernel/devicetree.rs +++ b/src/arch/riscv64/kernel/devicetree.rs @@ -147,7 +147,7 @@ pub fn init_drivers() { match gem::init_device( VirtAddr(gem_region.starting_address as u64), irq.try_into().unwrap(), - phy_addr.into(), + phy_addr, <[u8; 6]>::try_from(mac).expect("MAC with invalid length"), ) { Ok(drv) => register_driver(MmioDriver::GEMNet( From 14978f568bd69e1b46e41563a5a8cb0cc120d17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 1 May 2024 12:48:54 +0200 Subject: [PATCH 05/10] fix(gem-net): clippy::single_match MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/arch/riscv64/kernel/devicetree.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/arch/riscv64/kernel/devicetree.rs b/src/arch/riscv64/kernel/devicetree.rs index 6968aa7ab2..c96c776319 100644 --- a/src/arch/riscv64/kernel/devicetree.rs +++ b/src/arch/riscv64/kernel/devicetree.rs @@ -143,7 +143,6 @@ pub fn init_drivers() { as u64, ), ); - #[cfg(feature = "gem-net")] match gem::init_device( VirtAddr(gem_region.starting_address as u64), irq.try_into().unwrap(), @@ -153,7 +152,7 @@ pub fn init_drivers() { Ok(drv) => register_driver(MmioDriver::GEMNet( hermit_sync::InterruptSpinMutex::new(drv), )), - Err(_) => (), // could have information on error + Err(err) => error!("Could not initialize GEM driver: {err}"), } } From ca14f1931b10d4724ed06bc17e07d56a0a9d2798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 1 May 2024 12:52:44 +0200 Subject: [PATCH 06/10] fix(riscv64/devicetree): unused_imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/arch/riscv64/kernel/devicetree.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/arch/riscv64/kernel/devicetree.rs b/src/arch/riscv64/kernel/devicetree.rs index c96c776319..5681c6e3c3 100644 --- a/src/arch/riscv64/kernel/devicetree.rs +++ b/src/arch/riscv64/kernel/devicetree.rs @@ -5,14 +5,14 @@ use crate::arch::mm::VirtAddr; use crate::arch::riscv64::kernel::get_dtb_ptr; use crate::arch::riscv64::kernel::interrupts::init_plic; #[cfg(all(feature = "tcp", not(feature = "pci")))] -use crate::arch::riscv64::kernel::mmio::{self, MmioDriver}; +use crate::arch::riscv64::kernel::mmio::MmioDriver; use crate::arch::riscv64::mm::{paging, PhysAddr}; #[cfg(feature = "gem-net")] use crate::drivers::net::gem; +#[cfg(all(feature = "tcp", not(feature = "pci"), not(feature = "gem-net")))] +use crate::drivers::virtio::transport::mmio::{self as mmio_virtio, VirtioDriver}; #[cfg(all(feature = "tcp", not(feature = "pci")))] -use crate::drivers::virtio::transport::mmio::{ - self as mmio_virtio, DevId, MmioRegisterLayout, VirtioDriver, -}; +use crate::drivers::virtio::transport::mmio::{DevId, MmioRegisterLayout}; #[cfg(all(feature = "tcp", not(feature = "pci")))] use crate::kernel::mmio::register_driver; From b8baadff5d01e68e1c4b34b79b4295dc6c75c6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 1 May 2024 12:53:18 +0200 Subject: [PATCH 07/10] fix(gem-net): clippy::redundant_field_names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/drivers/net/gem.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/drivers/net/gem.rs b/src/drivers/net/gem.rs index e007aade51..2d54ac348d 100644 --- a/src/drivers/net/gem.rs +++ b/src/drivers/net/gem.rs @@ -691,16 +691,16 @@ pub fn init_device( ); Ok(GEMDriver { - gem: gem, + gem, mtu: 1500, - irq: irq, - mac: mac, + irq, + mac, rx_counter: 0, - rxbuffer: rxbuffer, - rxbuffer_list: rxbuffer_list, + rxbuffer, + rxbuffer_list, tx_counter: 0, - txbuffer: txbuffer, - txbuffer_list: txbuffer_list, + txbuffer, + txbuffer_list, }) } From d8d33bcc3bfa2627ab3e0a900aef5e6b7c10b2eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 1 May 2024 12:54:35 +0200 Subject: [PATCH 08/10] fix(gem-net): unsafe_op_in_unsafe_fn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/drivers/net/gem.rs | 58 +++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/src/drivers/net/gem.rs b/src/drivers/net/gem.rs index 2d54ac348d..2d599088f1 100644 --- a/src/drivers/net/gem.rs +++ b/src/drivers/net/gem.rs @@ -705,36 +705,42 @@ pub fn init_device( } unsafe fn phy_read(gem: *mut Registers, addr: u32, reg: PhyReg) -> u16 { - // Check that no MDIO operation is in progress - wait_for_mdio(gem); - // Initiate the data shift operation over MDIO - (*gem).phy_maintenance.write( - PHYMaintenance::CLAUSE_22::SET - + PHYMaintenance::OP::READ - + PHYMaintenance::ADDR.val(addr) - + PHYMaintenance::REG.val(reg as u32) - + PHYMaintenance::MUST_10::MUST_BE_10, - ); - wait_for_mdio(gem); - (*gem).phy_maintenance.read(PHYMaintenance::DATA) as u16 + unsafe { + // Check that no MDIO operation is in progress + wait_for_mdio(gem); + // Initiate the data shift operation over MDIO + (*gem).phy_maintenance.write( + PHYMaintenance::CLAUSE_22::SET + + PHYMaintenance::OP::READ + + PHYMaintenance::ADDR.val(addr) + + PHYMaintenance::REG.val(reg as u32) + + PHYMaintenance::MUST_10::MUST_BE_10, + ); + wait_for_mdio(gem); + (*gem).phy_maintenance.read(PHYMaintenance::DATA) as u16 + } } unsafe fn phy_write(gem: *mut Registers, addr: u32, reg: PhyReg, data: u16) { - // Check that no MDIO operation is in progress - wait_for_mdio(gem); - // Initiate the data shift operation over MDIO - (*gem).phy_maintenance.write( - PHYMaintenance::CLAUSE_22::SET - + PHYMaintenance::OP::WRITE - + PHYMaintenance::ADDR.val(addr) - + PHYMaintenance::REG.val(reg as u32) - + PHYMaintenance::MUST_10::MUST_BE_10 - + PHYMaintenance::DATA.val(data as u32), - ); - wait_for_mdio(gem); + unsafe { + // Check that no MDIO operation is in progress + wait_for_mdio(gem); + // Initiate the data shift operation over MDIO + (*gem).phy_maintenance.write( + PHYMaintenance::CLAUSE_22::SET + + PHYMaintenance::OP::WRITE + + PHYMaintenance::ADDR.val(addr) + + PHYMaintenance::REG.val(reg as u32) + + PHYMaintenance::MUST_10::MUST_BE_10 + + PHYMaintenance::DATA.val(data as u32), + ); + wait_for_mdio(gem); + } } unsafe fn wait_for_mdio(gem: *mut Registers) { - // Check that no MDIO operation is in progress - while !(*gem).network_status.is_set(NetworkStatus::PHY_MGMT_IDLE) {} + unsafe { + // Check that no MDIO operation is in progress + while !(*gem).network_status.is_set(NetworkStatus::PHY_MGMT_IDLE) {} + } } From f6264ff40f9be9852d1ffe4fdfe5202df29f5b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 1 May 2024 12:55:06 +0200 Subject: [PATCH 09/10] fix(gem-net): allow clippy::enum_variant_names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/drivers/net/gem.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/drivers/net/gem.rs b/src/drivers/net/gem.rs index 2d599088f1..89bb76e362 100644 --- a/src/drivers/net/gem.rs +++ b/src/drivers/net/gem.rs @@ -151,6 +151,7 @@ enum PhyReg { } /// PHY Status reg mask and offset +#[allow(clippy::enum_variant_names)] enum PhyStatus { ANCompleteOffset = 5, ANCompleteMask = 0x20, From 5e60f869e11f30e3fe04061fe309f98633719c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 1 May 2024 12:56:07 +0200 Subject: [PATCH 10/10] fix(xtask): disallow warnings for gem-net MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- xtask/src/clippy.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/xtask/src/clippy.rs b/xtask/src/clippy.rs index 003e45491d..324044b557 100644 --- a/xtask/src/clippy.rs +++ b/xtask/src/clippy.rs @@ -29,8 +29,6 @@ impl Clippy { cmd!(sh, "cargo clippy --target={triple}") .arg("--no-default-features") .arg("--features=gem-net,tcp") - .arg("--") - .arg("-Wwarnings") .run()?; }