@@ -54,30 +54,6 @@ impl RingIndexRange for ops::Range<RingIdx> {
5454 }
5555}
5656
57- /// A newtype of bool used for convenience in context with
58- /// packed queues wrap counter.
59- ///
60- /// For more details see Virtio specification v1.1. - 2.7.1
61- #[ derive( Copy , Clone , Debug ) ]
62- struct WrapCount ( bool ) ;
63-
64- impl WrapCount {
65- /// Returns a new WrapCount struct initialized to true or 1.
66- ///
67- /// See virtio specification v1.1. - 2.7.1
68- fn new ( ) -> Self {
69- WrapCount ( true )
70- }
71-
72- /// Toggles a given wrap count to respectiver other value.
73- ///
74- /// If WrapCount(true) returns WrapCount(false),
75- /// if WrapCount(false) returns WrapCount(true).
76- fn wrap ( & mut self ) {
77- self . 0 = !self . 0 ;
78- }
79- }
80-
8157/// Structure which allows to control raw ring and operate easily on it
8258struct DescriptorRing {
8359 ring : Box < [ pvirtq:: Desc ] , DeviceAlloc > ,
@@ -92,8 +68,8 @@ struct DescriptorRing {
9268 /// Where to expect the next used descriptor by the device
9369 poll_index : u16 ,
9470 /// See Virtio specification v1.1. - 2.7.1
95- drv_wc : WrapCount ,
96- dev_wc : WrapCount ,
71+ drv_wc : bool ,
72+ dev_wc : bool ,
9773 /// Memory pool controls the amount of "free floating" descriptors
9874 /// See [MemPool] docs for detail.
9975 mem_pool : MemPool ,
@@ -115,8 +91,8 @@ impl DescriptorRing {
11591 write_index : 0 ,
11692 capacity : size,
11793 poll_index : 0 ,
118- drv_wc : WrapCount :: new ( ) ,
119- dev_wc : WrapCount :: new ( ) ,
94+ drv_wc : true ,
95+ dev_wc : true ,
12096 mem_pool : MemPool :: new ( size) ,
12197 }
12298 }
@@ -168,7 +144,7 @@ impl DescriptorRing {
168144 ) ;
169145 Ok ( RingIdx {
170146 off : self . write_index ,
171- wrap : self . drv_wc . 0 . into ( ) ,
147+ wrap : self . drv_wc . into ( ) ,
172148 } )
173149 }
174150
@@ -251,7 +227,7 @@ impl DescriptorRing {
251227
252228 /// Returns the [DescF] with the avail and used flags set in accordance
253229 /// with the VIRTIO specification v1.2 - 2.8.1 (i.e. avail flag set to match
254- /// the driver WrapCount and the used flag set to NOT match the WrapCount ).
230+ /// the driver wrap counter and the used flag set to NOT match the wrap counter ).
255231 ///
256232 /// This function is defined on the whole ring rather than only the
257233 /// wrap counter to ensure that it is not called on the incorrect
@@ -261,20 +237,20 @@ impl DescriptorRing {
261237 /// for the cases in which the modification of the flag needs to be
262238 /// deferred (e.g. patched dispatches, chained buffers).
263239 fn to_marked_avail ( & self , mut flags : DescF ) -> DescF {
264- flags. set ( virtq:: DescF :: AVAIL , self . drv_wc . 0 ) ;
265- flags. set ( virtq:: DescF :: USED , !self . drv_wc . 0 ) ;
240+ flags. set ( virtq:: DescF :: AVAIL , self . drv_wc ) ;
241+ flags. set ( virtq:: DescF :: USED , !self . drv_wc ) ;
266242 flags
267243 }
268244
269245 /// Checks the avail and used flags to see if the descriptor is marked
270246 /// as used by the device in accordance with the
271- /// VIRTIO specification v1.2 - 2.8.1 (i.e. they match the device WrapCount )
247+ /// VIRTIO specification v1.2 - 2.8.1 (i.e. they match the device wrap counter )
272248 ///
273249 /// This function is defined on the whole ring rather than only the
274250 /// wrap counter to ensure that it is not called on the incorrect
275251 /// wrap counter (i.e. driver wrap counter) by accident.
276252 fn is_marked_used ( & self , flags : DescF ) -> bool {
277- if self . dev_wc . 0 {
253+ if self . dev_wc {
278254 flags. contains ( virtq:: DescF :: AVAIL | virtq:: DescF :: USED )
279255 } else {
280256 !flags. intersects ( virtq:: DescF :: AVAIL | virtq:: DescF :: USED )
@@ -338,7 +314,7 @@ impl ReadCtrl<'_> {
338314
339315 fn incrmt ( & mut self ) {
340316 if self . desc_ring . poll_index + 1 == self . modulo {
341- self . desc_ring . dev_wc . wrap ( ) ;
317+ self . desc_ring . dev_wc ^= true ;
342318 }
343319
344320 // Increment capacity as we have one more free now!
@@ -376,7 +352,7 @@ impl WriteCtrl<'_> {
376352 /// Incrementing index by one. The index wrappes around to zero when
377353 /// reaching (modulo -1).
378354 ///
379- /// Also takes care of wrapping the WrapCount of the associated
355+ /// Also takes care of wrapping the wrap counter of the associated
380356 /// DescriptorRing.
381357 fn incrmt ( & mut self ) {
382358 // Firstly check if we are at all allowed to write a descriptor
@@ -385,7 +361,7 @@ impl WriteCtrl<'_> {
385361 // check if increment wrapped around end of ring
386362 // then also wrap the wrap counter.
387363 if self . position + 1 == self . modulo {
388- self . desc_ring . drv_wc . wrap ( ) ;
364+ self . desc_ring . drv_wc ^= true ;
389365 }
390366 // Also update the write_index
391367 self . desc_ring . write_index = ( self . desc_ring . write_index + 1 ) % self . modulo ;
@@ -402,7 +378,7 @@ impl WriteCtrl<'_> {
402378 // the device does not see an incomplete chain).
403379 self . first_flags = self . desc_ring . to_marked_avail ( incomplete_desc. flags ) ;
404380 } else {
405- // Set avail and used according to the current WrapCount .
381+ // Set avail and used according to the current wrap counter .
406382 incomplete_desc. flags = self . desc_ring . to_marked_avail ( incomplete_desc. flags ) ;
407383 }
408384 self . desc_ring . ring [ usize:: from ( self . position ) ] = incomplete_desc;
0 commit comments