1
1
use core:: sync:: atomic:: { self , Ordering } ;
2
2
3
- use crate :: dma:: { generic_ring:: RawDescriptor , PacketId } ;
3
+ use crate :: dma:: { generic_ring:: RawDescriptor , Cache , PacketId } ;
4
4
5
5
#[ cfg( feature = "ptp" ) ]
6
6
use crate :: ptp:: Timestamp ;
@@ -122,9 +122,7 @@ pub use consts::*;
122
122
#[ derive( Clone , Copy ) ]
123
123
pub struct TxDescriptor {
124
124
inner_raw : RawDescriptor ,
125
- packet_id : Option < PacketId > ,
126
- #[ cfg( feature = "ptp" ) ]
127
- _padding : Option < Timestamp > ,
125
+ cache : Cache ,
128
126
}
129
127
130
128
impl Default for TxDescriptor {
@@ -138,9 +136,7 @@ impl TxDescriptor {
138
136
pub const fn new ( ) -> Self {
139
137
Self {
140
138
inner_raw : RawDescriptor :: new ( ) ,
141
- packet_id : None ,
142
- #[ cfg( feature = "ptp" ) ]
143
- _padding : None ,
139
+ cache : Cache :: new ( ) ,
144
140
}
145
141
}
146
142
@@ -152,7 +148,7 @@ impl TxDescriptor {
152
148
pub ( super ) fn setup ( & mut self ) {
153
149
// Zero-out all fields in the descriptor
154
150
( 0 ..4 ) . for_each ( |n| unsafe { self . inner_raw . write ( n, 0 ) } ) ;
155
- self . packet_id . take ( ) ;
151
+ self . cache . set_id_and_clear_ts ( None ) ;
156
152
}
157
153
158
154
pub ( super ) fn is_owned ( & self ) -> bool {
@@ -178,7 +174,7 @@ impl TxDescriptor {
178
174
}
179
175
}
180
176
181
- self . packet_id = packet_id ;
177
+ self . cache . set_id_and_clear_ts ( packet_id) ;
182
178
183
179
// "Preceding reads and writes cannot be moved past subsequent writes."
184
180
atomic:: fence ( Ordering :: Release ) ;
@@ -230,9 +226,14 @@ impl TxDescriptor {
230
226
#[ cfg( feature = "ptp" ) ]
231
227
impl TxDescriptor {
232
228
pub ( super ) fn has_packet_id ( & self , packet_id : & PacketId ) -> bool {
233
- self . packet_id . as_ref ( ) == Some ( packet_id)
229
+ self . cache . id ( ) . as_ref ( ) == Some ( packet_id)
234
230
}
235
231
232
+ /// For the TxDescriptor we ignore [`Cache::ts`] because:
233
+ /// * We're only really using the cache so that the size of RxDescriptor and TxDescriptor
234
+ /// is the same.
235
+ /// * We want to be able to retrieve the timestamp immutably.
236
+ /// * The Timestamp in the TX descriptor is valid until we perform another transmission.
236
237
pub ( super ) fn timestamp ( & self ) -> Option < Timestamp > {
237
238
let contains_timestamp = ( self . inner_raw . read ( 3 ) & TXDESC_3_TTSS ) == TXDESC_3_TTSS ;
238
239
0 commit comments