Skip to content

Commit 6b67521

Browse files
committed
drivers/nfb: allow dynamic offset for timestamp in frame header
1 parent 2cf81fc commit 6b67521

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

drivers/net/nfb/nfb_rx.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ nfb_eth_rx_queue_init(struct nfb_device *nfb,
104104
const struct rte_pktmbuf_pool_private *mbp_priv =
105105
rte_mempool_get_priv(mb_pool);
106106

107+
struct nfb_fdt_packed_item pi;
108+
int off;
109+
107110
if (nfb == NULL)
108111
return -EINVAL;
109112

@@ -122,6 +125,22 @@ nfb_eth_rx_queue_init(struct nfb_device *nfb,
122125
rxq->rx_bytes = 0;
123126
rxq->err_pkts = 0;
124127

128+
rxq->timestamp_off = -1;
129+
rxq->timestamp_vld_off = -1;
130+
/* FIXME: checking only header ID 0 */
131+
off = ndp_header_fdt_node_offset(nfb_get_fdt(priv->nfb), 0, 0);
132+
if (off >= 0 && nfb_timestamp_dynfield_offset >= 0) {
133+
pi = nfb_fdt_packed_item_by_name(nfb_get_fdt(priv->nfb), off, "timestamp");
134+
if (/*pi.offset >= 0 && */pi.width == 64 && pi.offset % 64 == 0)
135+
rxq->timestamp_off = pi.offset / 8;
136+
137+
pi = nfb_fdt_packed_item_by_name(nfb_get_fdt(priv->nfb), off, "timestamp.vld");
138+
if (/*pi.offset >= 0 && */pi.width == 1) {
139+
rxq->timestamp_vld_off = pi.offset / 8;
140+
rxq->timestamp_vld_mask = (1 << (pi.offset % 8));
141+
}
142+
}
143+
125144
return 0;
126145
}
127146

drivers/net/nfb/nfb_rx.h

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <rte_mbuf.h>
1414
#include <rte_mbuf_dyn.h>
1515
#include <rte_ethdev.h>
16+
#include <rte_time.h>
1617

1718
extern uint64_t nfb_timestamp_rx_dynflag;
1819
extern 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);
124129
int
125130
nfb_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

Comments
 (0)