@@ -60,13 +60,13 @@ struct DescriptorRing {
6060 // Controlling variables for the ring
6161 //
6262 /// where to insert available descriptors next
63- write_index : u16 ,
63+ /// See Virtio specification v1.1. - 2.7.1
64+ write_index : EventSuppressDesc ,
6465 /// How much descriptors can be inserted
6566 capacity : u16 ,
6667 /// Where to expect the next used descriptor by the device
6768 poll_index : u16 ,
6869 /// See Virtio specification v1.1. - 2.7.1
69- drv_wc : bool ,
7070 dev_wc : bool ,
7171 /// Memory pool controls the amount of "free floating" descriptors
7272 /// See [MemPool] docs for detail.
@@ -83,13 +83,16 @@ impl DescriptorRing {
8383 . collect :: < Vec < _ > > ( )
8484 . into_boxed_slice ( ) ;
8585
86+ let write_index = EventSuppressDesc :: new ( )
87+ . with_desc_event_off ( 0 )
88+ . with_desc_event_wrap ( 1 ) ;
89+
8690 DescriptorRing {
8791 ring,
8892 tkn_ref_ring,
89- write_index : 0 ,
93+ write_index,
9094 capacity : size,
9195 poll_index : 0 ,
92- drv_wc : true ,
9396 dev_wc : true ,
9497 mem_pool : MemPool :: new ( size) ,
9598 }
@@ -141,9 +144,7 @@ impl DescriptorRing {
141144 first_ctrl_settings. 2 ,
142145 ) ;
143146
144- Ok ( EventSuppressDesc :: new ( )
145- . with_desc_event_off ( self . write_index )
146- . with_desc_event_wrap ( self . drv_wc . into ( ) ) )
147+ Ok ( self . write_index )
147148 }
148149
149150 fn push ( & mut self , tkn : TransferToken < pvirtq:: Desc > ) -> Result < EventSuppressDesc , VirtqError > {
@@ -187,8 +188,8 @@ impl DescriptorRing {
187188 fn get_write_ctrler ( & mut self ) -> Result < WriteCtrl < ' _ > , VirtqError > {
188189 let desc_id = self . mem_pool . pool . pop ( ) . ok_or ( VirtqError :: NoDescrAvail ) ?;
189190 Ok ( WriteCtrl {
190- start : self . write_index ,
191- position : self . write_index ,
191+ start : self . write_index . desc_event_off ( ) ,
192+ position : self . write_index . desc_event_off ( ) ,
192193 modulo : u16:: try_from ( self . ring . len ( ) ) . unwrap ( ) ,
193194 first_flags : DescF :: empty ( ) ,
194195 buff_id : desc_id,
@@ -235,8 +236,9 @@ impl DescriptorRing {
235236 /// for the cases in which the modification of the flag needs to be
236237 /// deferred (e.g. patched dispatches, chained buffers).
237238 fn to_marked_avail ( & self , mut flags : DescF ) -> DescF {
238- flags. set ( virtq:: DescF :: AVAIL , self . drv_wc ) ;
239- flags. set ( virtq:: DescF :: USED , !self . drv_wc ) ;
239+ let avail = self . write_index . desc_event_wrap ( ) != 0 ;
240+ flags. set ( virtq:: DescF :: AVAIL , avail) ;
241+ flags. set ( virtq:: DescF :: USED , !avail) ;
240242 flags
241243 }
242244
@@ -356,13 +358,21 @@ impl WriteCtrl<'_> {
356358 // Firstly check if we are at all allowed to write a descriptor
357359 assert ! ( self . desc_ring. capacity != 0 ) ;
358360 self . desc_ring . capacity -= 1 ;
361+
362+ let mut desc = self . desc_ring . write_index ;
363+
359364 // check if increment wrapped around end of ring
360365 // then also wrap the wrap counter.
361366 if self . position + 1 == self . modulo {
362- self . desc_ring . drv_wc ^= true ;
367+ let wrap = desc. desc_event_wrap ( ) ^ 1 ;
368+ desc. set_desc_event_wrap ( wrap) ;
363369 }
370+
364371 // Also update the write_index
365- self . desc_ring . write_index = ( self . desc_ring . write_index + 1 ) % self . modulo ;
372+ let off = ( desc. desc_event_off ( ) + 1 ) % self . modulo ;
373+ desc. set_desc_event_off ( off) ;
374+
375+ self . desc_ring . write_index = desc;
366376
367377 self . position = ( self . position + 1 ) % self . modulo ;
368378 }
0 commit comments