Skip to content

Commit 81b0552

Browse files
vcgomesJeff Kirsher
authored andcommitted
igc: Add support for RX timestamping
This adds support for timestamping received packets. It is based on the i210, as many features of i225 work the same way. The main difference from i210 is that i225 has support for choosing the timer register to use when timestamping packets. Right now, we only support using timer 0. The other difference is that i225 stores two timestamps in the receive descriptor, right now, we only retrieve one. Signed-off-by: Vinicius Costa Gomes <[email protected]> Tested-by: Aaron Brown <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 5f29580 commit 81b0552

File tree

5 files changed

+340
-0
lines changed

5 files changed

+340
-0
lines changed

drivers/net/ethernet/intel/igc/igc.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ extern char igc_driver_version[];
107107
#define AUTO_ALL_MODES 0
108108
#define IGC_RX_HDR_LEN IGC_RXBUFFER_256
109109

110+
/* Transmit and receive latency (for PTP timestamps) */
111+
/* FIXME: These values were estimated using the ones that i210 has as
112+
* basis, they seem to provide good numbers with ptp4l/phc2sys, but we
113+
* need to confirm them.
114+
*/
115+
#define IGC_I225_TX_LATENCY_10 9542
116+
#define IGC_I225_TX_LATENCY_100 1024
117+
#define IGC_I225_TX_LATENCY_1000 178
118+
#define IGC_I225_TX_LATENCY_2500 64
119+
#define IGC_I225_RX_LATENCY_10 20662
120+
#define IGC_I225_RX_LATENCY_100 2213
121+
#define IGC_I225_RX_LATENCY_1000 448
122+
#define IGC_I225_RX_LATENCY_2500 160
123+
110124
/* RX and TX descriptor control thresholds.
111125
* PTHRESH - MAC will consider prefetch if it has fewer than this number of
112126
* descriptors available in its onboard memory.
@@ -539,6 +553,9 @@ int igc_erase_filter(struct igc_adapter *adapter,
539553
void igc_ptp_init(struct igc_adapter *adapter);
540554
void igc_ptp_reset(struct igc_adapter *adapter);
541555
void igc_ptp_stop(struct igc_adapter *adapter);
556+
void igc_ptp_rx_rgtstamp(struct igc_q_vector *q_vector, struct sk_buff *skb);
557+
void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, void *va,
558+
struct sk_buff *skb);
542559
int igc_ptp_set_ts_config(struct net_device *netdev, struct ifreq *ifr);
543560
int igc_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr);
544561
#define igc_rx_pg_size(_ring) (PAGE_SIZE << igc_rx_pg_order(_ring))

drivers/net/ethernet/intel/igc/igc_defines.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,21 @@
314314
#define IGC_RCTL_RDMTS_HALF 0x00000000 /* Rx desc min thresh size */
315315
#define IGC_RCTL_BAM 0x00008000 /* broadcast enable */
316316

317+
/* Split Replication Receive Control */
318+
#define IGC_SRRCTL_TIMESTAMP 0x40000000
319+
#define IGC_SRRCTL_TIMER1SEL(timer) (((timer) & 0x3) << 14)
320+
#define IGC_SRRCTL_TIMER0SEL(timer) (((timer) & 0x3) << 17)
321+
317322
/* Receive Descriptor bit definitions */
318323
#define IGC_RXD_STAT_EOP 0x02 /* End of Packet */
319324
#define IGC_RXD_STAT_IXSM 0x04 /* Ignore checksum */
320325
#define IGC_RXD_STAT_UDPCS 0x10 /* UDP xsum calculated */
321326
#define IGC_RXD_STAT_TCPCS 0x20 /* TCP xsum calculated */
322327

328+
/* Advanced Receive Descriptor bit definitions */
329+
#define IGC_RXDADV_STAT_TSIP 0x08000 /* timestamp in packet */
330+
#define IGC_RXDADV_STAT_TS 0x10000 /* Pkt was time stamped */
331+
323332
#define IGC_RXDEXT_STATERR_CE 0x01000000
324333
#define IGC_RXDEXT_STATERR_SE 0x02000000
325334
#define IGC_RXDEXT_STATERR_SEQ 0x04000000
@@ -356,6 +365,7 @@
356365

357366
#define I225_RXPBSIZE_DEFAULT 0x000000A2 /* RXPBSIZE default */
358367
#define I225_TXPBSIZE_DEFAULT 0x04000014 /* TXPBSIZE default */
368+
#define IGC_RXPBS_CFG_TS_EN 0x80000000 /* Timestamp in Rx buffer */
359369

360370
/* Time Sync Interrupt Causes */
361371
#define IGC_TSICR_SYS_WRAP BIT(0) /* SYSTIM Wrap around. */
@@ -367,6 +377,34 @@
367377

368378
#define IGC_TSICR_INTERRUPTS IGC_TSICR_TXTS
369379

380+
/* PTP Queue Filter */
381+
#define IGC_ETQF_1588 BIT(30)
382+
383+
#define IGC_FTQF_VF_BP 0x00008000
384+
#define IGC_FTQF_1588_TIME_STAMP 0x08000000
385+
#define IGC_FTQF_MASK 0xF0000000
386+
#define IGC_FTQF_MASK_PROTO_BP 0x10000000
387+
388+
/* Time Sync Receive Control bit definitions */
389+
#define IGC_TSYNCRXCTL_VALID 0x00000001 /* Rx timestamp valid */
390+
#define IGC_TSYNCRXCTL_TYPE_MASK 0x0000000E /* Rx type mask */
391+
#define IGC_TSYNCRXCTL_TYPE_L2_V2 0x00
392+
#define IGC_TSYNCRXCTL_TYPE_L4_V1 0x02
393+
#define IGC_TSYNCRXCTL_TYPE_L2_L4_V2 0x04
394+
#define IGC_TSYNCRXCTL_TYPE_ALL 0x08
395+
#define IGC_TSYNCRXCTL_TYPE_EVENT_V2 0x0A
396+
#define IGC_TSYNCRXCTL_ENABLED 0x00000010 /* enable Rx timestamping */
397+
#define IGC_TSYNCRXCTL_SYSCFI 0x00000020 /* Sys clock frequency */
398+
399+
/* Time Sync Receive Configuration */
400+
#define IGC_TSYNCRXCFG_PTP_V1_CTRLT_MASK 0x000000FF
401+
#define IGC_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE 0x00
402+
#define IGC_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE 0x01
403+
404+
/* Immediate Interrupt Receive Extended */
405+
#define IGC_IMIREXT_CTRL_BP 0x00080000 /* Bypass check of ctrl bits */
406+
#define IGC_IMIREXT_SIZE_BP 0x00001000 /* Packet size bypass */
407+
370408
/* Receive Checksum Control */
371409
#define IGC_RXCSUM_CRCOFL 0x00000800 /* CRC32 offload enable */
372410
#define IGC_RXCSUM_PCSD 0x00002000 /* packet checksum disabled */

drivers/net/ethernet/intel/igc/igc_main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,10 @@ static void igc_process_skb_fields(struct igc_ring *rx_ring,
12991299

13001300
igc_rx_checksum(rx_ring, rx_desc, skb);
13011301

1302+
if (igc_test_staterr(rx_desc, IGC_RXDADV_STAT_TS) &&
1303+
!igc_test_staterr(rx_desc, IGC_RXDADV_STAT_TSIP))
1304+
igc_ptp_rx_rgtstamp(rx_ring->q_vector, skb);
1305+
13021306
skb_record_rx_queue(skb, rx_ring->queue_index);
13031307

13041308
skb->protocol = eth_type_trans(skb, rx_ring->netdev);
@@ -1418,6 +1422,12 @@ static struct sk_buff *igc_construct_skb(struct igc_ring *rx_ring,
14181422
if (unlikely(!skb))
14191423
return NULL;
14201424

1425+
if (unlikely(igc_test_staterr(rx_desc, IGC_RXDADV_STAT_TSIP))) {
1426+
igc_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
1427+
va += IGC_TS_HDR_LEN;
1428+
size -= IGC_TS_HDR_LEN;
1429+
}
1430+
14211431
/* Determine available headroom for copy */
14221432
headlen = size;
14231433
if (headlen > IGC_RX_HDR_LEN)

0 commit comments

Comments
 (0)