mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-21 11:46:33 +00:00
修复内核的clippy检查报错 (#637)
修复内核的clippy检查报错 --------- Co-authored-by: Samuel Dai <947309196@qq.com> Co-authored-by: Donkey Kane <109840258+xiaolin2004@users.noreply.github.com> Co-authored-by: themildwind <107623059+themildwind@users.noreply.github.com> Co-authored-by: GnoCiYeH <heyicong@dragonos.org> Co-authored-by: MemoryShore <105195940+MemoryShore@users.noreply.github.com> Co-authored-by: 曾俊 <110876916+ZZJJWarth@users.noreply.github.com> Co-authored-by: sun5etop <146408999+sun5etop@users.noreply.github.com> Co-authored-by: hmt <114841534+1037827920@users.noreply.github.com> Co-authored-by: laokengwt <143977175+laokengwt@users.noreply.github.com> Co-authored-by: TTaq <103996388+TTaq@users.noreply.github.com> Co-authored-by: Jomo <2512364506@qq.com> Co-authored-by: Samuel Dai <samuka007@qq.com> Co-authored-by: sspphh <112558065+sspphh@users.noreply.github.com>
This commit is contained in:
@ -155,7 +155,7 @@ impl E1000EBuffer {
|
||||
return self.length;
|
||||
}
|
||||
// 释放buffer内部的dma_pages,需要小心使用
|
||||
pub fn free_buffer(self) -> () {
|
||||
pub fn free_buffer(self) {
|
||||
if self.length != 0 {
|
||||
unsafe { dma_dealloc(self.paddr, self.buffer, E1000E_DMA_PAGES) };
|
||||
}
|
||||
@ -274,7 +274,7 @@ impl E1000EDevice {
|
||||
// close the interrupt
|
||||
volwrite!(interrupt_regs, imc, E1000E_IMC_CLEAR);
|
||||
let mut gcr = volread!(pcie_regs, gcr);
|
||||
gcr = gcr | (1 << 22);
|
||||
gcr |= 1 << 22;
|
||||
volwrite!(pcie_regs, gcr, gcr);
|
||||
compiler_fence(Ordering::AcqRel);
|
||||
// PHY Initialization 14.8.1
|
||||
@ -291,11 +291,11 @@ impl E1000EDevice {
|
||||
let ral = unsafe { volread!(ra_regs, ral0) };
|
||||
let rah = unsafe { volread!(ra_regs, rah0) };
|
||||
let mac: [u8; 6] = [
|
||||
((ral >> 0) & 0xFF) as u8,
|
||||
(ral & 0xFF) as u8,
|
||||
((ral >> 8) & 0xFF) as u8,
|
||||
((ral >> 16) & 0xFF) as u8,
|
||||
((ral >> 24) & 0xFF) as u8,
|
||||
((rah >> 0) & 0xFF) as u8,
|
||||
(rah & 0xFF) as u8,
|
||||
((rah >> 8) & 0xFF) as u8,
|
||||
];
|
||||
// 初始化receive和transimit descriptor环形队列
|
||||
@ -319,17 +319,17 @@ impl E1000EDevice {
|
||||
|
||||
// 初始化缓冲区与descriptor,descriptor 中的addr字典应当指向buffer的物理地址
|
||||
// Receive buffers of appropriate size should be allocated and pointers to these buffers should be stored in the descriptor ring.
|
||||
for i in 0..recv_ring_length {
|
||||
for ring in recv_desc_ring.iter_mut().take(recv_ring_length) {
|
||||
let buffer = E1000EBuffer::new(PAGE_SIZE);
|
||||
recv_desc_ring[i].addr = buffer.as_paddr() as u64;
|
||||
recv_desc_ring[i].status = 0;
|
||||
ring.addr = buffer.as_paddr() as u64;
|
||||
ring.status = 0;
|
||||
recv_buffers.push(buffer);
|
||||
}
|
||||
// Same as receive buffers
|
||||
for i in 0..trans_ring_length {
|
||||
for ring in trans_desc_ring.iter_mut().take(recv_ring_length) {
|
||||
let buffer = E1000EBuffer::new(PAGE_SIZE);
|
||||
trans_desc_ring[i].addr = buffer.as_paddr() as u64;
|
||||
trans_desc_ring[i].status = 1;
|
||||
ring.addr = buffer.as_paddr() as u64;
|
||||
ring.status = 1;
|
||||
trans_buffers.push(buffer);
|
||||
}
|
||||
|
||||
@ -340,7 +340,7 @@ impl E1000EDevice {
|
||||
while mta_adress != vaddress + E1000E_MTA_REGS_END_OFFSET {
|
||||
let mta: NonNull<MTARegs> = get_register_ptr(mta_adress, 0);
|
||||
unsafe { volwrite!(mta, mta, 0) };
|
||||
mta_adress = mta_adress + 4;
|
||||
mta_adress += 4;
|
||||
}
|
||||
// 连续的寄存器读-写操作,放在同一个unsafe块中
|
||||
unsafe {
|
||||
@ -491,8 +491,8 @@ impl E1000EDevice {
|
||||
pub fn e1000e_intr_set(&mut self, state: bool) {
|
||||
let mut ims = unsafe { volread!(self.interrupt_regs, ims) };
|
||||
match state {
|
||||
true => ims = ims | E1000E_IMS_RXT0,
|
||||
false => ims = ims & !E1000E_IMS_RXT0,
|
||||
true => ims |= E1000E_IMS_RXT0,
|
||||
false => ims &= !E1000E_IMS_RXT0,
|
||||
}
|
||||
unsafe { volwrite!(self.interrupt_regs, ims, ims) };
|
||||
}
|
||||
@ -512,8 +512,7 @@ impl E1000EDevice {
|
||||
// close interrupt
|
||||
self.e1000e_intr_set(false);
|
||||
loop {
|
||||
if self.napi_buffer_tail == self.napi_buffer_head && self.napi_buffer_empty == false
|
||||
{
|
||||
if self.napi_buffer_tail == self.napi_buffer_head && !self.napi_buffer_empty {
|
||||
// napi缓冲队列已满,停止收包
|
||||
// napi queue is full, stop
|
||||
break;
|
||||
@ -593,7 +592,7 @@ pub extern "C" fn rs_e1000e_init() {
|
||||
e1000e_init();
|
||||
}
|
||||
|
||||
pub fn e1000e_init() -> () {
|
||||
pub fn e1000e_init() {
|
||||
match e1000e_probe() {
|
||||
Ok(_code) => {
|
||||
kinfo!("Successfully init e1000e device!");
|
||||
|
@ -34,6 +34,8 @@ pub struct E1000ETxToken {
|
||||
pub struct E1000EDriver {
|
||||
pub inner: Arc<SpinLock<E1000EDevice>>,
|
||||
}
|
||||
unsafe impl Send for E1000EDriver {}
|
||||
unsafe impl Sync for E1000EDriver {}
|
||||
|
||||
/// @brief 网卡驱动的包裹器,这是为了获取网卡驱动的可变引用而设计的。
|
||||
/// 参阅virtio_net.rs
|
||||
@ -54,6 +56,7 @@ impl DerefMut for E1000EDriverWrapper {
|
||||
}
|
||||
|
||||
impl E1000EDriverWrapper {
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
fn force_get_mut(&self) -> &mut E1000EDriver {
|
||||
unsafe { &mut *self.0.get() }
|
||||
}
|
||||
@ -76,7 +79,7 @@ impl phy::RxToken for E1000ERxToken {
|
||||
where
|
||||
F: FnOnce(&mut [u8]) -> R,
|
||||
{
|
||||
let result = f(&mut self.0.as_mut_slice());
|
||||
let result = f(self.0.as_mut_slice());
|
||||
self.0.free_buffer();
|
||||
return result;
|
||||
}
|
||||
@ -97,6 +100,7 @@ impl phy::TxToken for E1000ETxToken {
|
||||
}
|
||||
|
||||
impl E1000EDriver {
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
pub fn new(device: E1000EDevice) -> Self {
|
||||
let mut iface_config = smoltcp::iface::Config::new();
|
||||
|
||||
@ -253,11 +257,11 @@ impl NetDriver for E1000EInterface {
|
||||
|
||||
self.iface.lock().update_ip_addrs(|addrs| {
|
||||
let dest = addrs.iter_mut().next();
|
||||
if let None = dest {
|
||||
addrs.push(ip_addrs[0]).expect("Push ipCidr failed: full");
|
||||
} else {
|
||||
let dest = dest.unwrap();
|
||||
|
||||
if let Some(dest) = dest {
|
||||
*dest = ip_addrs[0];
|
||||
} else {
|
||||
addrs.push(ip_addrs[0]).expect("Push ipCidr failed: full");
|
||||
}
|
||||
});
|
||||
return Ok(());
|
||||
|
@ -1,2 +1,3 @@
|
||||
#[allow(clippy::module_inception)]
|
||||
pub mod e1000e;
|
||||
pub mod e1000e_driver;
|
||||
|
Reference in New Issue
Block a user