1313#include <rte_mbuf.h>
1414#include <rte_mbuf_dyn.h>
1515#include <rte_ethdev.h>
16+ #include <rte_time.h>
1617
1718extern uint64_t nfb_timestamp_rx_dynflag ;
1819extern int nfb_timestamp_dynfield_offset ;
@@ -34,6 +35,10 @@ struct ndp_rx_queue {
3435 struct rte_mempool * mb_pool ; /* memory pool to allocate packets */
3536 uint16_t buf_size ; /* mbuf size */
3637
38+ int16_t timestamp_off ;
39+ int16_t timestamp_vld_off ;
40+ uint8_t timestamp_vld_mask ;
41+
3742 volatile uint64_t rx_pkts ; /* packets read */
3843 volatile uint64_t rx_bytes ; /* bytes read */
3944 volatile uint64_t err_pkts ; /* erroneous packets */
@@ -124,6 +129,29 @@ nfb_eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id);
124129int
125130nfb_eth_rx_queue_stop (struct rte_eth_dev * dev , uint16_t rxq_id );
126131
132+ static inline void nfb_rx_fetch_timestamp (struct ndp_rx_queue * q , struct rte_mbuf * mbuf ,
133+ const unsigned char * header , int header_length )
134+ {
135+ rte_mbuf_timestamp_t timestamp ;
136+
137+ /* INFO: already checked in nfb_eth_rx_queue_init */
138+ if (/*nfb_timestamp_dynfield_offset < 0 || */ q -> timestamp_off < 0 )
139+ return ;
140+
141+ if (header_length < q -> timestamp_off + 8 )
142+ return ;
143+
144+ /* seconds */
145+ timestamp = rte_le_to_cpu_32 (* ((const uint32_t * ) (header + q -> timestamp_off + 4 )));
146+ timestamp *= NSEC_PER_SEC ;
147+ /* nanoseconds */
148+ timestamp += rte_le_to_cpu_32 (* ((const uint32_t * ) (header + q -> timestamp_off + 0 )));
149+
150+ * nfb_timestamp_dynfield (mbuf ) = timestamp ;
151+ if (header_length > (q -> timestamp_vld_off ) && header [q -> timestamp_vld_off ] & q -> timestamp_vld_mask )
152+ mbuf -> ol_flags |= nfb_timestamp_rx_dynflag ;
153+ }
154+
127155/**
128156 * DPDK callback for RX.
129157 *
@@ -197,21 +225,7 @@ nfb_eth_ndp_rx(void *queue,
197225 mbuf -> port = ndp -> in_port ;
198226 mbuf -> ol_flags = 0 ;
199227
200- if (nfb_timestamp_dynfield_offset >= 0 ) {
201- rte_mbuf_timestamp_t timestamp ;
202-
203- /* nanoseconds */
204- timestamp =
205- rte_le_to_cpu_32 (* ((uint32_t * )
206- (packets [i ].header + 4 )));
207- timestamp <<= 32 ;
208- /* seconds */
209- timestamp |=
210- rte_le_to_cpu_32 (* ((uint32_t * )
211- (packets [i ].header + 8 )));
212- * nfb_timestamp_dynfield (mbuf ) = timestamp ;
213- mbuf -> ol_flags |= nfb_timestamp_rx_dynflag ;
214- }
228+ nfb_rx_fetch_timestamp (ndp , mbuf , packets [i ].header , packets [i ].header_length );
215229
216230 bufs [num_rx ++ ] = mbuf ;
217231 num_bytes += packet_size ;
0 commit comments