@@ -65,9 +65,9 @@ struct DescriptorRing {
6565 /// How much descriptors can be inserted
6666 capacity : u16 ,
6767 /// Where to expect the next used descriptor by the device
68- poll_index : u16 ,
68+ ///
6969 /// See Virtio specification v1.1. - 2.7.1
70- dev_wc : bool ,
70+ poll_index : EventSuppressDesc ,
7171 /// Memory pool controls the amount of "free floating" descriptors
7272 /// See [MemPool] docs for detail.
7373 mem_pool : MemPool ,
@@ -87,13 +87,14 @@ impl DescriptorRing {
8787 . with_desc_event_off ( 0 )
8888 . with_desc_event_wrap ( 1 ) ;
8989
90+ let poll_index = write_index;
91+
9092 DescriptorRing {
9193 ring,
9294 tkn_ref_ring,
9395 write_index,
9496 capacity : size,
95- poll_index : 0 ,
96- dev_wc : true ,
97+ poll_index,
9798 mem_pool : MemPool :: new ( size) ,
9899 }
99100 }
@@ -202,7 +203,7 @@ impl DescriptorRing {
202203 /// to read the queue correctly.
203204 fn get_read_ctrler ( & mut self ) -> ReadCtrl < ' _ > {
204205 ReadCtrl {
205- position : self . poll_index ,
206+ position : self . poll_index . desc_event_off ( ) ,
206207 modulo : u16:: try_from ( self . ring . len ( ) ) . unwrap ( ) ,
207208
208209 desc_ring : self ,
@@ -250,7 +251,7 @@ impl DescriptorRing {
250251 /// wrap counter to ensure that it is not called on the incorrect
251252 /// wrap counter (i.e. driver wrap counter) by accident.
252253 fn is_marked_used ( & self , flags : DescF ) -> bool {
253- if self . dev_wc {
254+ if self . poll_index . desc_event_wrap ( ) != 0 {
254255 flags. contains ( virtq:: DescF :: AVAIL | virtq:: DescF :: USED )
255256 } else {
256257 !flags. intersects ( virtq:: DescF :: AVAIL | virtq:: DescF :: USED )
@@ -313,16 +314,23 @@ impl ReadCtrl<'_> {
313314 }
314315
315316 fn incrmt ( & mut self ) {
316- if self . desc_ring . poll_index + 1 == self . modulo {
317- self . desc_ring . dev_wc ^= true ;
317+ let mut desc = self . desc_ring . poll_index ;
318+
319+ if desc. desc_event_off ( ) + 1 == self . modulo {
320+ let wrap = desc. desc_event_wrap ( ) ^ 1 ;
321+ desc. set_desc_event_wrap ( wrap) ;
318322 }
319323
324+ let off = ( desc. desc_event_off ( ) + 1 ) % self . modulo ;
325+ desc. set_desc_event_off ( off) ;
326+
327+ self . desc_ring . poll_index = desc;
328+
329+ self . position = desc. desc_event_off ( ) ;
330+
320331 // Increment capacity as we have one more free now!
321332 assert ! ( self . desc_ring. capacity <= u16 :: try_from( self . desc_ring. ring. len( ) ) . unwrap( ) ) ;
322333 self . desc_ring . capacity += 1 ;
323-
324- self . desc_ring . poll_index = ( self . desc_ring . poll_index + 1 ) % self . modulo ;
325- self . position = self . desc_ring . poll_index ;
326334 }
327335}
328336
@@ -617,7 +625,7 @@ impl Virtq for PackedVq {
617625 }
618626
619627 fn has_used_buffers ( & self ) -> bool {
620- let desc = & self . descr_ring . ring [ usize:: from ( self . descr_ring . poll_index ) ] ;
628+ let desc = & self . descr_ring . ring [ usize:: from ( self . descr_ring . poll_index . desc_event_off ( ) ) ] ;
621629 self . descr_ring . is_marked_used ( desc. flags )
622630 }
623631}
0 commit comments