@@ -19,14 +19,18 @@ use pci_types::{
1919use crate :: arch:: pci:: PciConfigRegion ;
2020#[ cfg( feature = "fuse" ) ]
2121use crate :: drivers:: fs:: virtio_fs:: VirtioFsDriver ;
22- #[ cfg( any( feature = "tcp" , feature = "udp" ) ) ]
22+ #[ cfg( all(
23+ any( feature = "tcp" , feature = "udp" ) ,
24+ any(
25+ feature = "virtio-net" ,
26+ all( target_arch = "riscv64" , feature = "gem-net" ) ,
27+ all( target_arch = "x86_64" , feature = "rtl8139" ) ,
28+ )
29+ ) ) ]
2330use crate :: drivers:: net:: NetworkDriver ;
2431#[ cfg( all( target_arch = "x86_64" , feature = "rtl8139" ) ) ]
2532use crate :: drivers:: net:: rtl8139:: { self , RTL8139Driver } ;
26- #[ cfg( all(
27- not( all( target_arch = "x86_64" , feature = "rtl8139" ) ) ,
28- any( feature = "tcp" , feature = "udp" )
29- ) ) ]
33+ #[ cfg( all( feature = "virtio-net" , any( feature = "tcp" , feature = "udp" ) ) ) ]
3034use crate :: drivers:: net:: virtio:: VirtioNetDriver ;
3135#[ cfg( any(
3236 all(
@@ -333,10 +337,7 @@ pub(crate) enum PciDriver {
333337 VirtioFs ( InterruptTicketMutex < VirtioFsDriver > ) ,
334338 #[ cfg( feature = "vsock" ) ]
335339 VirtioVsock ( InterruptTicketMutex < VirtioVsockDriver > ) ,
336- #[ cfg( all(
337- not( all( target_arch = "x86_64" , feature = "rtl8139" ) ) ,
338- any( feature = "tcp" , feature = "udp" )
339- ) ) ]
340+ #[ cfg( all( feature = "virtio-net" , any( feature = "tcp" , feature = "udp" ) ) ) ]
340341 VirtioNet ( InterruptTicketMutex < VirtioNetDriver > ) ,
341342 #[ cfg( all(
342343 target_arch = "x86_64" ,
@@ -347,16 +348,14 @@ pub(crate) enum PciDriver {
347348}
348349
349350impl PciDriver {
350- #[ cfg( all(
351- not( all( target_arch = "x86_64" , feature = "rtl8139" ) ) ,
352- any( feature = "tcp" , feature = "udp" )
353- ) ) ]
351+ #[ cfg( all( feature = "virtio-net" , any( feature = "tcp" , feature = "udp" ) ) ) ]
354352 fn get_network_driver ( & self ) -> Option < & InterruptTicketMutex < VirtioNetDriver > > {
355- #[ allow( unreachable_patterns) ]
356- match self {
357- Self :: VirtioNet ( drv) => Some ( drv) ,
358- _ => None ,
353+ #[ allow( irrefutable_let_patterns) ]
354+ if let Self :: VirtioNet ( drv) = self {
355+ return Some ( drv) ;
359356 }
357+
358+ None
360359 }
361360
362361 #[ cfg( all(
@@ -365,29 +364,32 @@ impl PciDriver {
365364 any( feature = "tcp" , feature = "udp" )
366365 ) ) ]
367366 fn get_network_driver ( & self ) -> Option < & InterruptTicketMutex < RTL8139Driver > > {
368- #[ allow( unreachable_patterns) ]
369- match self {
370- Self :: RTL8139Net ( drv) => Some ( drv) ,
371- _ => None ,
367+ #[ allow( irrefutable_let_patterns) ]
368+ if let Self :: RTL8139Net ( drv) = self {
369+ return Some ( drv) ;
372370 }
371+
372+ None
373373 }
374374
375375 #[ cfg( feature = "vsock" ) ]
376376 fn get_vsock_driver ( & self ) -> Option < & InterruptTicketMutex < VirtioVsockDriver > > {
377- #[ allow( unreachable_patterns) ]
378- match self {
379- Self :: VirtioVsock ( drv) => Some ( drv) ,
380- _ => None ,
377+ #[ allow( irrefutable_let_patterns) ]
378+ if let Self :: VirtioVsock ( drv) = self {
379+ return Some ( drv) ;
381380 }
381+
382+ None
382383 }
383384
384385 #[ cfg( feature = "fuse" ) ]
385386 fn get_filesystem_driver ( & self ) -> Option < & InterruptTicketMutex < VirtioFsDriver > > {
386- match self {
387- Self :: VirtioFs ( drv) => Some ( drv) ,
388- #[ allow( unreachable_patterns) ]
389- _ => None ,
387+ #[ allow( irrefutable_let_patterns) ]
388+ if let Self :: VirtioFs ( drv) = self {
389+ return Some ( drv) ;
390390 }
391+
392+ None
391393 }
392394
393395 fn get_interrupt_handler ( & self ) -> ( InterruptLine , fn ( ) ) {
@@ -421,10 +423,7 @@ impl PciDriver {
421423
422424 ( irq_number, rtl8139_handler)
423425 }
424- #[ cfg( all(
425- not( all( target_arch = "x86_64" , feature = "rtl8139" ) ) ,
426- any( feature = "tcp" , feature = "udp" )
427- ) ) ]
426+ #[ cfg( all( feature = "virtio-net" , any( feature = "tcp" , feature = "udp" ) ) ) ]
428427 Self :: VirtioNet ( drv) => {
429428 fn network_handler ( ) {
430429 if let Some ( driver) = get_network_driver ( ) {
@@ -473,10 +472,7 @@ pub(crate) fn get_interrupt_handlers() -> HashMap<InterruptLine, InterruptHandle
473472 handlers
474473}
475474
476- #[ cfg( all(
477- not( all( target_arch = "x86_64" , feature = "rtl8139" ) ) ,
478- any( feature = "tcp" , feature = "udp" )
479- ) ) ]
475+ #[ cfg( all( feature = "virtio-net" , any( feature = "tcp" , feature = "udp" ) ) ) ]
480476pub ( crate ) fn get_network_driver ( ) -> Option < & ' static InterruptTicketMutex < VirtioNetDriver > > {
481477 PCI_DRIVERS
482478 . get ( ) ?
@@ -525,18 +521,12 @@ pub(crate) fn init() {
525521 ) ;
526522
527523 #[ cfg( any(
528- all(
529- any( feature = "tcp" , feature = "udp" ) ,
530- not( all( target_arch = "x86_64" , feature = "rtl8139" ) )
531- ) ,
524+ all( any( feature = "tcp" , feature = "udp" ) , feature = "virtio-net" ) ,
532525 feature = "fuse" ,
533526 feature = "vsock"
534527 ) ) ]
535528 match pci_virtio:: init_device ( adapter) {
536- #[ cfg( all(
537- not( all( target_arch = "x86_64" , feature = "rtl8139" ) ) ,
538- any( feature = "tcp" , feature = "udp" )
539- ) ) ]
529+ #[ cfg( all( feature = "virtio-net" , any( feature = "tcp" , feature = "udp" ) ) ) ]
540530 Ok ( VirtioDriver :: Network ( drv) ) => {
541531 register_driver ( PciDriver :: VirtioNet ( InterruptTicketMutex :: new ( drv) ) ) ;
542532 }
0 commit comments