1515// You should have received a copy of the GNU General Public License
1616// along with Aero. If not, see <https://www.gnu.org/licenses/>.
1717
18+ use alloc:: boxed:: Box ;
1819use alloc:: sync:: Arc ;
1920use spin:: Once ;
2021
@@ -23,9 +24,11 @@ use crate::arch::interrupts::{self, InterruptStack};
2324use crate :: drivers:: pci:: * ;
2425use crate :: mem:: paging:: * ;
2526use crate :: userland:: scheduler;
27+ use crate :: utils:: dma:: DmaAllocator ;
2628use crate :: utils:: sync:: { Mutex , WaitQueue } ;
2729
28- use crate :: net:: { self , ethernet, MacAddr , NetworkDevice , NetworkDriver , PacketBaseTrait } ;
30+ use crate :: net:: { self , ethernet, NetworkDevice , NetworkDriver } ;
31+ use netstack:: data_link:: MacAddr ;
2932
3033const TX_DESC_NUM : u32 = 32 ;
3134const TX_DESC_SIZE : u32 = TX_DESC_NUM * core:: mem:: size_of :: < TxDescriptor > ( ) as u32 ;
@@ -374,35 +377,35 @@ impl E1000 {
374377 }
375378 }
376379
377- fn send ( & mut self , packet : net :: Packet < net :: Eth > ) {
380+ fn send ( & mut self , packet : Box < [ u8 ] , DmaAllocator > ) {
378381 let cur = self . tx_cur ;
379382 let ring = self . tx_ring ( ) ;
380383
381- ring[ cur] . addr = unsafe { packet. addr ( ) - crate :: PHYSICAL_MEMORY_OFFSET } ;
384+ ring[ cur] . addr =
385+ unsafe { VirtAddr :: new ( packet. as_ptr ( ) as u64 ) - crate :: PHYSICAL_MEMORY_OFFSET } ;
382386 ring[ cur] . length = packet. len ( ) as _ ;
383387 ring[ cur] . cmd = 0b1011 ;
384388 ring[ cur] . status = TStatus :: empty ( ) ;
385389
386390 self . tx_cur = ( self . tx_cur + 1 ) % TX_DESC_NUM as usize ;
387391
388392 self . write ( Register :: TxDescTail , self . tx_cur as u32 ) ;
393+ core:: mem:: forget ( packet) ; // FIXME: hack
389394 }
390395
391- fn recv ( & mut self ) -> Option < net:: RecvPacket > {
396+ fn recv < ' a > ( & mut self ) -> Option < net:: RecvPacket < ' a > > {
392397 let id = self . rx_cur ;
393398 let desc = & mut self . rx_ring ( ) [ id] ;
394399
395400 if desc. status & 0x1 != 0x1 {
396401 return None ;
397402 }
398403
399- Some ( net:: RecvPacket {
400- packet : net:: Packet :: < ethernet:: Eth > :: new (
401- PhysAddr :: new ( desc. addr ) . as_hhdm_virt ( ) ,
402- desc. length as usize ,
403- ) ,
404- id,
405- } )
404+ let packet = PhysAddr :: new ( desc. addr )
405+ . as_hhdm_virt ( )
406+ . as_bytes_mut ( desc. length as usize ) ;
407+
408+ Some ( net:: RecvPacket { packet, id } )
406409 }
407410
408411 fn recv_end ( & mut self , id : usize ) {
@@ -595,7 +598,7 @@ impl Device {
595598}
596599
597600impl NetworkDriver for Device {
598- fn send ( & self , packet : net :: Packet < net :: Eth > ) {
601+ fn send ( & self , packet : Box < [ u8 ] , DmaAllocator > ) {
599602 self . e1000 . lock_irq ( ) . send ( packet)
600603 }
601604
@@ -619,7 +622,7 @@ impl NetworkDriver for Device {
619622 self . e1000 . lock_irq ( ) . recv_end ( packet_id)
620623 }
621624
622- fn mac ( & self ) -> net :: MacAddr {
625+ fn mac ( & self ) -> MacAddr {
623626 self . e1000 . lock_irq ( ) . mac
624627 }
625628}
0 commit comments