Skip to content

Commit

Permalink
Merge pull request #1163 from hermit-os/gem_net-clippy
Browse files Browse the repository at this point in the history
fix(gem-net): clippy warnings
  • Loading branch information
mkroening authored May 1, 2024
2 parents 30104f1 + 5e60f86 commit 7cf44bb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 49 deletions.
13 changes: 6 additions & 7 deletions src/arch/riscv64/kernel/devicetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -143,17 +143,16 @@ 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(),
phy_addr.into(),
phy_addr,
<[u8; 6]>::try_from(mac).expect("MAC with invalid length"),
) {
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}"),
}
}

Expand Down
84 changes: 44 additions & 40 deletions src/drivers/net/gem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ enum PhyReg {
}

/// PHY Status reg mask and offset
#[allow(clippy::enum_variant_names)]
enum PhyStatus {
ANCompleteOffset = 5,
ANCompleteMask = 0x20,
Expand Down Expand Up @@ -299,10 +300,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)> {
Expand Down Expand Up @@ -406,7 +404,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?)
Expand Down Expand Up @@ -507,8 +505,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);

Expand Down Expand Up @@ -694,50 +692,56 @@ 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,
})
}

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) {}
}
}
2 changes: 0 additions & 2 deletions xtask/src/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
}

Expand Down

0 comments on commit 7cf44bb

Please sign in to comment.