Skip to contentSkip to conversation

net/iavf: support Rx timestamp on flex descriptor

PATCH Superseded Simei Su 3 participants 14 messages Apr 8, 2022 – May 10, 2022 Network drivers

lore
Share & tools
lore

Simei Su

author
#0 lore raw

cover net/iavf: support Rx timestamp on flex descriptor

[PATCH v1 1/3] add related ops and structure for Rx timestamp in virtual channel. [PATCH v1 2/3] add support for Rx timestamp on flex descriptor in driver. [PATCH v1 3/3] improve performance with Rx timestamp enabled.

Simei Su (2):
common/iavf: support Rx timestamp in virtual channel net/iavf: enable Rx timestamp on Flex Descriptor

Wenjun Wu (1):
net/iavf: improve performance of Rx timestamp offload

 drivers/common/iavf/virtchnl.h          | 62 ++++++++++++++++++++++--
 drivers/net/iavf/iavf.h                 |  6 +++
 drivers/net/iavf/iavf_ethdev.c          | 34 ++++++++++++++
 drivers/net/iavf/iavf_rxtx.c            | 72 ++++++++++++++++++++++++++++
 drivers/net/iavf/iavf_rxtx.h            | 21 +++++++++
 drivers/net/iavf/iavf_rxtx_vec_common.h |  3 ++
 drivers/net/iavf/iavf_vchnl.c           | 83 ++++++++++++++++++++++++++++-----
 7 files changed, 267 insertions(+), 14 deletions(-)
Signature · 1 line
2.9.5
author
#1 lore raw

PATCH 1/3 common/iavf: support Rx timestamp in virtual channel

Add new ops and structures to support VF to support Rx timestamp on flex descriptor.

"VIRTCHNL_OP_1588_PTP_GET_CAPS" ops is sent by the VF to request PTP capablilities and responded by the PF with capabilities enabled for that VF.

"VIRTCHNL_OP_1588_PTP_GET_TIME" ops is sent by the VF to request the current time of the PHC. The PF will respond by reading the device time and reporting it back to the VF.

---
 drivers/common/iavf/virtchnl.h | 62 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 3 deletions(-)
drivers/common/iavf/virtchnl.h +59 -3
index 3e44eca..d3a99e9 100644
@@ -159,6 +159,8 @@ enum virtchnl_ops {
 	VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 = 57,
 	VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2 = 58,
 	VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 = 59,
+	VIRTCHNL_OP_1588_PTP_GET_CAPS = 60,
+	VIRTCHNL_OP_1588_PTP_GET_TIME = 61,
 	VIRTCHNL_OP_GET_QOS_CAPS = 66,
 	VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP = 67,
 	VIRTCHNL_OP_ENABLE_QUEUES_V2 = 107,
@@ -274,6 +276,10 @@ static inline const char *virtchnl_op_str(enum virtchnl_ops v_opcode)
 		return "VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2";
 	case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
 		return "VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2";
+	case VIRTCHNL_OP_1588_PTP_GET_CAPS:
+		return "VIRTCHNL_OP_1588_PTP_GET_CAPS";
+	case VIRTCHNL_OP_1588_PTP_GET_TIME:
+		return "VIRTCHNL_OP_1588_PTP_GET_TIME";
 	case VIRTCHNL_OP_MAX:
 		return "VIRTCHNL_OP_MAX";
 	default:
@@ -409,8 +415,7 @@ VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
 #define VIRTCHNL_VF_OFFLOAD_FDIR_PF		BIT(28)
 #define VIRTCHNL_VF_OFFLOAD_QOS		BIT(29)
 #define VIRTCHNL_VF_CAP_DCF			BIT(30)
-	/* BIT(31) is reserved */
-
+#define VIRTCHNL_VF_CAP_PTP			BIT(31)
 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
 			       VIRTCHNL_VF_OFFLOAD_VLAN | \
 			       VIRTCHNL_VF_OFFLOAD_RSS_PF)
@@ -496,6 +501,18 @@ enum virtchnl_rx_desc_id_bitmasks {
 	/* 22 through 63 are reserved */
 };
 
+/* virtchnl_rxq_info_flags
+ *
+ * Definition of bits in the flags field of the virtchnl_rxq_info structure.
+ */
+enum virtchnl_rxq_info_flags {
+	/* If the VIRTCHNL_PTP_RX_TSTAMP bit of the flag field is set, this is
+	 * a request to enable Rx timestamp. Other flag bits are currently
+	 * reserved and they may be extended in the future.
+	 */
+	VIRTCHNL_PTP_RX_TSTAMP = BIT(0),
+};
+
 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
  * VF sends this message to set up parameters for one RX queue.
  * External data buffer contains one instance of virtchnl_rxq_info.
@@ -524,7 +541,8 @@ struct virtchnl_rxq_info {
 	 * with VIRTCHNL_RXDID_1_32B_BASE.
 	 */
 	u8 rxdid;
-	u8 pad1[2];
+	u8 flags; /* see virtchnl_rxq_info_flags */
+	u8 pad1;
 	u64 dma_ring_addr;
 
 	/* see enum virtchnl_rx_hsplit; deprecated with AVF 1.0 */
@@ -1978,6 +1996,38 @@ struct virtchnl_queue_vector_maps {
 
 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_queue_vector_maps);
 
+#define VIRTCHNL_1588_PTP_CAP_RX_TSTAMP		BIT(1)
+#define VIRTCHNL_1588_PTP_CAP_READ_PHC          BIT(2)
+
+struct virtchnl_phc_regs {
+	u32 clock_hi;
+	u32 clock_lo;
+	u8 pcie_region;
+	u8 rsvd[15];
+};
+
+VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_phc_regs);
+
+struct virtchnl_ptp_caps {
+	struct virtchnl_phc_regs phc_regs;
+	u32 caps;
+	s32 max_adj;
+	u8 tx_tstamp_idx;
+	u8 n_ext_ts;
+	u8 n_per_out;
+	u8 n_pins;
+	u8 tx_tstamp_format;
+	u8 rsvd[11];
+};
+
+VIRTCHNL_CHECK_STRUCT_LEN(48, virtchnl_ptp_caps);
+
+struct virtchnl_phc_time {
+	uint64_t time;
+	uint8_t rsvd[8];
+};
+
+VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_phc_time);
 
 /* Since VF messages are limited by u16 size, precalculate the maximum possible
  * values of nested elements in virtchnl structures that virtual channel can
@@ -2271,6 +2321,12 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
 	case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
 		valid_len = sizeof(struct virtchnl_vlan_setting);
 		break;
+	case VIRTCHNL_OP_1588_PTP_GET_CAPS:
+		valid_len = sizeof(struct virtchnl_ptp_caps);
+		break;
+	case VIRTCHNL_OP_1588_PTP_GET_TIME:
+		valid_len = sizeof(struct virtchnl_phc_time);
+		break;
 	case VIRTCHNL_OP_ENABLE_QUEUES_V2:
 	case VIRTCHNL_OP_DISABLE_QUEUES_V2:
 		valid_len = sizeof(struct virtchnl_del_ena_dis_queues);
Signature · 1 line
2.9.5
author
#2 lore raw

PATCH 2/3 net/iavf: enable Rx timestamp on Flex Descriptor

In reply to Simei Su

Dump Rx timestamp value into dynamic mbuf field by flex descriptor. This feature is turned on by dev config "enable-rx-timestamp". Currently, it's only supported under scalar path.

---
 drivers/net/iavf/iavf.h                 |  5 ++
 drivers/net/iavf/iavf_ethdev.c          | 26 +++++++++++
 drivers/net/iavf/iavf_rxtx.c            | 58 +++++++++++++++++++++++
 drivers/net/iavf/iavf_rxtx.h            | 22 +++++++++
 drivers/net/iavf/iavf_rxtx_vec_common.h |  3 ++
 drivers/net/iavf/iavf_vchnl.c           | 83 ++++++++++++++++++++++++++++-----
 6 files changed, 186 insertions(+), 11 deletions(-)
drivers/net/iavf/iavf.h +5 -0
index a01d18e..2838b5e 100644
@@ -257,6 +257,8 @@ struct iavf_info {
 	struct iavf_tm_conf tm_conf;
 
 	struct rte_eth_dev *eth_dev;
+
+	uint32_t ptp_caps;
 };
 
 #define IAVF_MAX_PKT_TYPE 1024
@@ -300,6 +302,7 @@ struct iavf_adapter {
 	bool stopped;
 	uint16_t fdir_ref_cnt;
 	struct iavf_devargs devargs;
+	uint64_t phc_time;
 };
 
 /* IAVF_DEV_PRIVATE_TO */
@@ -460,4 +463,6 @@ int iavf_ipsec_crypto_request(struct iavf_adapter *adapter,
 		uint8_t *msg, size_t msg_len,
 		uint8_t *resp_msg, size_t resp_msg_len);
 extern const struct rte_tm_ops iavf_tm_ops;
+int iavf_get_ptp_cap(struct iavf_adapter *adapter);
+int iavf_get_phc_time(struct iavf_adapter *adapter);
 #endif /* _IAVF_ETHDEV_H_ */
drivers/net/iavf/iavf_ethdev.c +26 -0
index d6190ac..704c174 100644
@@ -35,6 +35,9 @@
 /* devargs */
 #define IAVF_PROTO_XTR_ARG         "proto_xtr"
 
+uint64_t iavf_timestamp_dynflag;
+int iavf_timestamp_dynfield_offset = -1;
+
 static const char * const iavf_valid_args[] = {
 	IAVF_PROTO_XTR_ARG,
 	NULL
@@ -685,6 +688,7 @@ iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
 	struct rte_eth_dev_data *dev_data = dev->data;
 	uint16_t buf_size, max_pkt_len;
 	uint32_t frame_size = dev->data->mtu + IAVF_ETH_OVERHEAD;
+	enum iavf_status err;
 
 	buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
 
@@ -703,6 +707,18 @@ iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
 		return -EINVAL;
 	}
 
+	if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
+		/* Register mbuf field and flag for Rx timestamp */
+		err = rte_mbuf_dyn_rx_timestamp_register(
+			&iavf_timestamp_dynfield_offset,
+			&iavf_timestamp_dynflag);
+		if (err) {
+			PMD_DRV_LOG(ERR,
+				"Cannot register mbuf field/flag for timestamp");
+			return -EINVAL;
+		}
+	}
+
 	rxq->max_pkt_len = max_pkt_len;
 	if ((dev_data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) ||
 	    rxq->max_pkt_len > buf_size) {
@@ -945,6 +961,13 @@ iavf_dev_start(struct rte_eth_dev *dev)
 			return -1;
 		}
 
+	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) {
+		if (iavf_get_ptp_cap(adapter)) {
+			PMD_INIT_LOG(ERR, "Failed to get ptp capability");
+			return -1;
+		}
+	}
+
 	if (iavf_init_queues(dev) != 0) {
 		PMD_DRV_LOG(ERR, "failed to do Queue init");
 		return -1;
@@ -1087,6 +1110,9 @@ iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_CRC)
 		dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
 
+	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP)
+		dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
+
 	if (iavf_ipsec_crypto_supported(adapter)) {
 		dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_SECURITY;
 		dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_SECURITY;
drivers/net/iavf/iavf_rxtx.c +58 -0

105 lines not on this page · raw message

drivers/net/iavf/iavf_rxtx.h +22 -0
index bf8aebb..37453c4 100644
@@ -72,6 +72,9 @@
 #define IAVF_TX_OFFLOAD_NOTSUP_MASK \
 		(RTE_MBUF_F_TX_OFFLOAD_MASK ^ IAVF_TX_OFFLOAD_MASK)
 
+extern uint64_t iavf_timestamp_dynflag;
+extern int iavf_timestamp_dynfield_offset;
+
 /**
  * Rx Flex Descriptors
  * These descriptors are used instead of the legacy version descriptors
@@ -219,6 +222,7 @@ struct iavf_rx_queue {
 		/* flexible descriptor metadata extraction offload flag */
 	struct iavf_rx_queue_stats stats;
 	uint64_t offloads;
+	uint32_t hw_register_set;
 };
 
 struct iavf_tx_entry {
@@ -778,6 +782,24 @@ void iavf_fdir_rx_proc_enable(struct iavf_adapter *ad, bool on)
 	}
 }
 
+static inline
+uint64_t iavf_tstamp_convert_32b_64b(uint64_t time, uint32_t in_timestamp)
+{
+	const uint64_t mask = 0xFFFFFFFF;
+	uint32_t delta;
+	uint64_t ns;
+
+	delta = (in_timestamp - (uint32_t)(time & mask));
+	if (delta > (mask / 2)) {
+		delta = ((uint32_t)(time & mask) - in_timestamp);
+		ns = time - delta;
+	} else {
+		ns = time + delta;
+	}
+
+	return ns;
+}
+
 #ifdef RTE_LIBRTE_IAVF_DEBUG_DUMP_DESC
 #define IAVF_DUMP_RX_DESC(rxq, desc, rx_id) \
 	iavf_dump_rx_descriptor(rxq, desc, rx_id)
drivers/net/iavf/iavf_rxtx_vec_common.h +3 -0
index 1fd37b7..a59cb2c 100644
@@ -231,6 +231,9 @@ iavf_rx_vec_queue_default(struct iavf_rx_queue *rxq)
 	if (rxq->proto_xtr != IAVF_PROTO_XTR_NONE)
 		return -1;
 
+	if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
+		return -1;
+
 	if (rxq->offloads & IAVF_RX_VECTOR_OFFLOAD)
 		return IAVF_VECTOR_OFFLOAD_PATH;
 
drivers/net/iavf/iavf_vchnl.c +72 -11

98 lines not on this page · raw message

Signature · 1 line
2.9.5
author
#3 lore raw

PATCH 3/3 net/iavf: improve performance of Rx timestamp offload

In reply to Simei Su

From: Wenjun Wu <[email protected]>

In this patch, We use CPU ticks instead of HW register to determin whether low 32 bits timestamp has turned over. It can avoid requesting register value frequently and improve receving performance.

---
 drivers/net/iavf/iavf.h        |  1 +
 drivers/net/iavf/iavf_ethdev.c |  8 +++++++
 drivers/net/iavf/iavf_rxtx.c   | 50 +++++++++++++++++++++++++++---------------
 drivers/net/iavf/iavf_rxtx.h   |  1 -
 4 files changed, 41 insertions(+), 19 deletions(-)
drivers/net/iavf/iavf.h +1 -0
index 2838b5e..ad5c0d4 100644
@@ -303,6 +303,7 @@ struct iavf_adapter {
 	uint16_t fdir_ref_cnt;
 	struct iavf_devargs devargs;
 	uint64_t phc_time;
+	uint64_t hw_time_update;
 };
 
 /* IAVF_DEV_PRIVATE_TO */
drivers/net/iavf/iavf_ethdev.c +8 -0
index 704c174..ffdc368 100644
@@ -1014,6 +1014,14 @@ iavf_dev_start(struct rte_eth_dev *dev)
 		goto err_mac;
 	}
 
+	if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
+		if (iavf_get_phc_time(adapter)) {
+			PMD_DRV_LOG(ERR, "get physical time failed");
+			goto err_mac;
+		}
+		adapter->hw_time_update = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
+	}
+
 	return 0;
 
 err_mac:
drivers/net/iavf/iavf_rxtx.c +32 -18

94 lines not on this page · raw message

drivers/net/iavf/iavf_rxtx.h +0 -1
index 37453c4..642b9a7 100644
@@ -222,7 +222,6 @@ struct iavf_rx_queue {
 		/* flexible descriptor metadata extraction offload flag */
 	struct iavf_rx_queue_stats stats;
 	uint64_t offloads;
-	uint32_t hw_register_set;
 };
 
 struct iavf_tx_entry {
Signature · 1 line
2.9.5
author
#4 lore raw

v2 cover net/iavf: support Rx timestamp on flex descriptor

In reply to Simei Su

[PATCH v2 1/3] add related ops and structure for Rx timestamp in virtual channel. [PATCH v2 2/3] add support for Rx timestamp on flex descriptor in driver. [PATCH v2 3/3] improve performance with Rx timestamp enabled.

v2:
* Add release notes and doc update.

Simei Su (3):
common/iavf: support Rx timestamp in virtual channel net/iavf: enable Rx timestamp on Flex Descriptor net/iavf: improve performance of Rx timestamp offload

 doc/guides/nics/features/iavf.ini       |  1 +
 doc/guides/rel_notes/release_22_07.rst  |  1 +
 drivers/common/iavf/virtchnl.h          | 62 +++++++++++++++++++++++-
 drivers/net/iavf/iavf.h                 |  6 +++
 drivers/net/iavf/iavf_ethdev.c          | 35 ++++++++++++++
 drivers/net/iavf/iavf_rxtx.c            | 73 +++++++++++++++++++++++++++++
 drivers/net/iavf/iavf_rxtx.h            | 21 +++++++++
 drivers/net/iavf/iavf_rxtx_vec_common.h |  3 ++
 drivers/net/iavf/iavf_vchnl.c           | 83 ++++++++++++++++++++++++++++-----
 9 files changed, 272 insertions(+), 13 deletions(-)
Signature · 1 line
2.9.5
author
#5 lore raw

PATCH v2 1/3 common/iavf: support Rx timestamp in virtual channel

Add new ops and structures to support VF to support Rx timestamp on flex descriptor.

"VIRTCHNL_OP_1588_PTP_GET_CAPS" ops is sent by the VF to request PTP capabilities and responded by the PF with capabilities enabled for that VF.

"VIRTCHNL_OP_1588_PTP_GET_TIME" ops is sent by the VF to request the current time of the PHC. The PF will respond by reading the device time and reporting it back to the VF.

---
 drivers/common/iavf/virtchnl.h | 62 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 60 insertions(+), 2 deletions(-)
drivers/common/iavf/virtchnl.h +60 -2
index 249ae6e..2d49f95 100644
@@ -159,6 +159,8 @@ enum virtchnl_ops {
 	VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 = 57,
 	VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2 = 58,
 	VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 = 59,
+	VIRTCHNL_OP_1588_PTP_GET_CAPS = 60,
+	VIRTCHNL_OP_1588_PTP_GET_TIME = 61,
 	VIRTCHNL_OP_GET_QOS_CAPS = 66,
 	VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP = 67,
 	VIRTCHNL_OP_ENABLE_QUEUES_V2 = 107,
@@ -276,6 +278,10 @@ static inline const char *virtchnl_op_str(enum virtchnl_ops v_opcode)
 		return "VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2";
 	case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
 		return "VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2";
+	case VIRTCHNL_OP_1588_PTP_GET_CAPS:
+		return "VIRTCHNL_OP_1588_PTP_GET_CAPS";
+	case VIRTCHNL_OP_1588_PTP_GET_TIME:
+		return "VIRTCHNL_OP_1588_PTP_GET_TIME";
 	case VIRTCHNL_OP_MAX:
 		return "VIRTCHNL_OP_MAX";
 	default:
@@ -411,7 +417,7 @@ VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
 #define VIRTCHNL_VF_OFFLOAD_FDIR_PF		BIT(28)
 #define VIRTCHNL_VF_OFFLOAD_QOS		BIT(29)
 #define VIRTCHNL_VF_CAP_DCF			BIT(30)
-	/* BIT(31) is reserved */
+#define VIRTCHNL_VF_CAP_PTP			BIT(31)
 
 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
 			       VIRTCHNL_VF_OFFLOAD_VLAN | \
@@ -498,6 +504,18 @@ enum virtchnl_rx_desc_id_bitmasks {
 	/* 22 through 63 are reserved */
 };
 
+/* virtchnl_rxq_info_flags
+ *
+ * Definition of bits in the flags field of the virtchnl_rxq_info structure.
+ */
+enum virtchnl_rxq_info_flags {
+	/* If the VIRTCHNL_PTP_RX_TSTAMP bit of the flag field is set, this is
+	 * a request to enable Rx timestamp. Other flag bits are currently
+	 * reserved and they may be extended in the future.
+	 */
+	VIRTCHNL_PTP_RX_TSTAMP = BIT(0),
+};
+
 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
  * VF sends this message to set up parameters for one RX queue.
  * External data buffer contains one instance of virtchnl_rxq_info.
@@ -526,7 +544,8 @@ struct virtchnl_rxq_info {
 	 * with VIRTCHNL_RXDID_1_32B_BASE.
 	 */
 	u8 rxdid;
-	u8 pad1[2];
+	u8 flags; /* see virtchnl_rxq_info_flags */
+	u8 pad1;
 	u64 dma_ring_addr;
 
 	/* see enum virtchnl_rx_hsplit; deprecated with AVF 1.0 */
@@ -2004,6 +2023,39 @@ struct virtchnl_quanta_cfg {
 
 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_quanta_cfg);
 
+#define VIRTCHNL_1588_PTP_CAP_RX_TSTAMP		BIT(1)
+#define VIRTCHNL_1588_PTP_CAP_READ_PHC		BIT(2)
+
+struct virtchnl_phc_regs {
+	u32 clock_hi;
+	u32 clock_lo;
+	u8 pcie_region;
+	u8 rsvd[15];
+};
+
+VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_phc_regs);
+
+struct virtchnl_ptp_caps {
+	struct virtchnl_phc_regs phc_regs;
+	u32 caps;
+	s32 max_adj;
+	u8 tx_tstamp_idx;
+	u8 n_ext_ts;
+	u8 n_per_out;
+	u8 n_pins;
+	u8 tx_tstamp_format;
+	u8 rsvd[11];
+};
+
+VIRTCHNL_CHECK_STRUCT_LEN(48, virtchnl_ptp_caps);
+
+struct virtchnl_phc_time {
+	u64 time;
+	u8 rsvd[8];
+};
+
+VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_phc_time);
+
 /* Since VF messages are limited by u16 size, precalculate the maximum possible
  * values of nested elements in virtchnl structures that virtual channel can
  * possibly handle in a single message.
@@ -2321,6 +2373,12 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
 	case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
 		valid_len = sizeof(struct virtchnl_vlan_setting);
 		break;
+	case VIRTCHNL_OP_1588_PTP_GET_CAPS:
+		valid_len = sizeof(struct virtchnl_ptp_caps);
+		break;
+	case VIRTCHNL_OP_1588_PTP_GET_TIME:
+		valid_len = sizeof(struct virtchnl_phc_time);
+		break;
 	case VIRTCHNL_OP_ENABLE_QUEUES_V2:
 	case VIRTCHNL_OP_DISABLE_QUEUES_V2:
 		valid_len = sizeof(struct virtchnl_del_ena_dis_queues);
Signature · 1 line
2.9.5
author
#6 lore raw

PATCH v2 2/3 net/iavf: enable Rx timestamp on Flex Descriptor

In reply to Simei Su

Dump Rx timestamp value into dynamic mbuf field by flex descriptor. This feature is turned on by dev config "enable-rx-timestamp". Currently, it's only supported under scalar path.

---
 doc/guides/nics/features/iavf.ini       |  1 +
 doc/guides/rel_notes/release_22_07.rst  |  1 +
 drivers/net/iavf/iavf.h                 |  5 ++
 drivers/net/iavf/iavf_ethdev.c          | 26 +++++++++++
 drivers/net/iavf/iavf_rxtx.c            | 58 +++++++++++++++++++++++
 drivers/net/iavf/iavf_rxtx.h            | 22 +++++++++
 drivers/net/iavf/iavf_rxtx_vec_common.h |  3 ++
 drivers/net/iavf/iavf_vchnl.c           | 83 ++++++++++++++++++++++++++++-----
 8 files changed, 188 insertions(+), 11 deletions(-)
doc/guides/nics/features/iavf.ini +1 -0
index 01f5142..5a0d9d8 100644
@@ -24,6 +24,7 @@ CRC offload          = Y
 VLAN offload         = Y
 L3 checksum offload  = P
 L4 checksum offload  = P
+Timestamp offload    = P
 Packet type parsing  = Y
 Rx descriptor status = Y
 Tx descriptor status = Y
doc/guides/rel_notes/release_22_07.rst +1 -0
index f1b4057..567f23d 100644
@@ -59,6 +59,7 @@ New Features
 
   * Added Tx QoS queue rate limitation support.
   * Added quanta size configuration support.
+  * Added ``DEV_RX_OFFLOAD_TIMESTAMP`` support.
 
 Removed Items
 -------------
drivers/net/iavf/iavf.h +5 -0
index c0a4a47..3255c93 100644
@@ -268,6 +268,8 @@ struct iavf_info {
 	struct iavf_tm_conf tm_conf;
 
 	struct rte_eth_dev *eth_dev;
+
+	uint32_t ptp_caps;
 };
 
 #define IAVF_MAX_PKT_TYPE 1024
@@ -312,6 +314,7 @@ struct iavf_adapter {
 	bool stopped;
 	uint16_t fdir_ref_cnt;
 	struct iavf_devargs devargs;
+	uint64_t phc_time;
 };
 
 /* IAVF_DEV_PRIVATE_TO */
@@ -476,4 +479,6 @@ int iavf_ipsec_crypto_request(struct iavf_adapter *adapter,
 		uint8_t *msg, size_t msg_len,
 		uint8_t *resp_msg, size_t resp_msg_len);
 extern const struct rte_tm_ops iavf_tm_ops;
+int iavf_get_ptp_cap(struct iavf_adapter *adapter);
+int iavf_get_phc_time(struct iavf_adapter *adapter);
 #endif /* _IAVF_ETHDEV_H_ */
drivers/net/iavf/iavf_ethdev.c +26 -0
index 7d093bd..89e4240 100644
@@ -36,6 +36,9 @@
 #define IAVF_PROTO_XTR_ARG         "proto_xtr"
 #define IAVF_QUANTA_SIZE_ARG       "quanta_size"
 
+uint64_t iavf_timestamp_dynflag;
+int iavf_timestamp_dynfield_offset = -1;
+
 static const char * const iavf_valid_args[] = {
 	IAVF_PROTO_XTR_ARG,
 	IAVF_QUANTA_SIZE_ARG,
@@ -687,6 +690,7 @@ iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
 	struct rte_eth_dev_data *dev_data = dev->data;
 	uint16_t buf_size, max_pkt_len;
 	uint32_t frame_size = dev->data->mtu + IAVF_ETH_OVERHEAD;
+	enum iavf_status err;
 
 	buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
 
@@ -705,6 +709,18 @@ iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
 		return -EINVAL;
 	}
 
+	if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
+		/* Register mbuf field and flag for Rx timestamp */
+		err = rte_mbuf_dyn_rx_timestamp_register(
+			&iavf_timestamp_dynfield_offset,
+			&iavf_timestamp_dynflag);
+		if (err) {
+			PMD_DRV_LOG(ERR,
+				    "Cannot register mbuf field/flag for timestamp");
+			return -EINVAL;
+		}
+	}
+
 	rxq->max_pkt_len = max_pkt_len;
 	if ((dev_data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) ||
 	    rxq->max_pkt_len > buf_size) {
@@ -947,6 +963,13 @@ iavf_dev_start(struct rte_eth_dev *dev)
 			return -1;
 		}
 
+	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) {
+		if (iavf_get_ptp_cap(adapter)) {
+			PMD_INIT_LOG(ERR, "Failed to get ptp capability");
+			return -1;
+		}
+	}
+
 	if (iavf_init_queues(dev) != 0) {
 		PMD_DRV_LOG(ERR, "failed to do Queue init");
 		return -1;
@@ -1092,6 +1115,9 @@ iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_CRC)
 		dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
 
+	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP)
+		dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
+
 	if (iavf_ipsec_crypto_supported(adapter)) {
 		dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_SECURITY;
 		dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_SECURITY;
drivers/net/iavf/iavf_rxtx.c +58 -0

105 lines not on this page · raw message

drivers/net/iavf/iavf_rxtx.h +22 -0
index bf8aebb..37453c4 100644
@@ -72,6 +72,9 @@
 #define IAVF_TX_OFFLOAD_NOTSUP_MASK \
 		(RTE_MBUF_F_TX_OFFLOAD_MASK ^ IAVF_TX_OFFLOAD_MASK)
 
+extern uint64_t iavf_timestamp_dynflag;
+extern int iavf_timestamp_dynfield_offset;
+
 /**
  * Rx Flex Descriptors
  * These descriptors are used instead of the legacy version descriptors
@@ -219,6 +222,7 @@ struct iavf_rx_queue {
 		/* flexible descriptor metadata extraction offload flag */
 	struct iavf_rx_queue_stats stats;
 	uint64_t offloads;
+	uint32_t hw_register_set;
 };
 
 struct iavf_tx_entry {
@@ -778,6 +782,24 @@ void iavf_fdir_rx_proc_enable(struct iavf_adapter *ad, bool on)
 	}
 }
 
+static inline
+uint64_t iavf_tstamp_convert_32b_64b(uint64_t time, uint32_t in_timestamp)
+{
+	const uint64_t mask = 0xFFFFFFFF;
+	uint32_t delta;
+	uint64_t ns;
+
+	delta = (in_timestamp - (uint32_t)(time & mask));
+	if (delta > (mask / 2)) {
+		delta = ((uint32_t)(time & mask) - in_timestamp);
+		ns = time - delta;
+	} else {
+		ns = time + delta;
+	}
+
+	return ns;
+}
+
 #ifdef RTE_LIBRTE_IAVF_DEBUG_DUMP_DESC
 #define IAVF_DUMP_RX_DESC(rxq, desc, rx_id) \
 	iavf_dump_rx_descriptor(rxq, desc, rx_id)
drivers/net/iavf/iavf_rxtx_vec_common.h +3 -0
index 1fd37b7..a59cb2c 100644
@@ -231,6 +231,9 @@ iavf_rx_vec_queue_default(struct iavf_rx_queue *rxq)
 	if (rxq->proto_xtr != IAVF_PROTO_XTR_NONE)
 		return -1;
 
+	if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
+		return -1;
+
 	if (rxq->offloads & IAVF_RX_VECTOR_OFFLOAD)
 		return IAVF_VECTOR_OFFLOAD_PATH;
 
drivers/net/iavf/iavf_vchnl.c +72 -11

98 lines not on this page · raw message

Signature · 1 line
2.9.5
author
#7 lore raw

PATCH v2 3/3 net/iavf: improve performance of Rx timestamp offload

In reply to Simei Su

In this patch, We use CPU ticks instead of HW register to determine whether low 32 bits timestamp has turned over. It can avoid requesting register value frequently and improve receiving performance.

---
 drivers/net/iavf/iavf.h        |  1 +
 drivers/net/iavf/iavf_ethdev.c |  9 ++++++++
 drivers/net/iavf/iavf_rxtx.c   | 51 +++++++++++++++++++++++++++---------------
 drivers/net/iavf/iavf_rxtx.h   |  1 -
 4 files changed, 43 insertions(+), 19 deletions(-)
drivers/net/iavf/iavf.h +1 -0
index 3255c93..dd83567 100644
@@ -315,6 +315,7 @@ struct iavf_adapter {
 	uint16_t fdir_ref_cnt;
 	struct iavf_devargs devargs;
 	uint64_t phc_time;
+	uint64_t hw_time_update;
 };
 
 /* IAVF_DEV_PRIVATE_TO */
drivers/net/iavf/iavf_ethdev.c +9 -0
index 89e4240..d1a2b53 100644
@@ -1019,6 +1019,15 @@ iavf_dev_start(struct rte_eth_dev *dev)
 		goto err_mac;
 	}
 
+	if (dev->data->dev_conf.rxmode.offloads &
+	    RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
+		if (iavf_get_phc_time(adapter)) {
+			PMD_DRV_LOG(ERR, "get physical time failed");
+			goto err_mac;
+		}
+		adapter->hw_time_update = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
+	}
+
 	return 0;
 
 err_mac:
drivers/net/iavf/iavf_rxtx.c +33 -18

96 lines not on this page · raw message

drivers/net/iavf/iavf_rxtx.h +0 -1
index 37453c4..642b9a7 100644
@@ -222,7 +222,6 @@ struct iavf_rx_queue {
 		/* flexible descriptor metadata extraction offload flag */
 	struct iavf_rx_queue_stats stats;
 	uint64_t offloads;
-	uint32_t hw_register_set;
 };
 
 struct iavf_tx_entry {
Signature · 1 line
2.9.5
author
#8 lore raw

v3 cover net/iavf: support Rx timestamp on flex descriptor

In reply to Simei Su

[PATCH v3 1/3] add related ops and structure for Rx timestamp in virtual channel. [PATCH v3 2/3] add support for Rx timestamp on flex descriptor in driver. [PATCH v3 3/3] improve performance with Rx timestamp enabled.

v3:
* Rebase code.
* Fix compile warning.

v2:
* Add release notes and doc update.

Simei Su (3):
common/iavf: support Rx timestamp in virtual channel net/iavf: enable Rx timestamp on Flex Descriptor net/iavf: improve performance of Rx timestamp offload

 doc/guides/nics/features/iavf.ini       |  1 +
 doc/guides/rel_notes/release_22_07.rst  |  2 +-
 drivers/common/iavf/virtchnl.h          | 62 +++++++++++++++++++++++-
 drivers/net/iavf/iavf.h                 |  6 +++
 drivers/net/iavf/iavf_ethdev.c          | 35 ++++++++++++++
 drivers/net/iavf/iavf_rxtx.c            | 74 +++++++++++++++++++++++++++++
 drivers/net/iavf/iavf_rxtx.h            | 21 +++++++++
 drivers/net/iavf/iavf_rxtx_vec_common.h |  3 ++
 drivers/net/iavf/iavf_vchnl.c           | 83 ++++++++++++++++++++++++++++-----
 9 files changed, 273 insertions(+), 14 deletions(-)
Signature · 1 line
2.9.5
author
#9 lore raw

PATCH v3 1/3 common/iavf: support Rx timestamp in virtual channel

Add new ops and structures to support VF to support Rx timestamp on flex descriptor.

"VIRTCHNL_OP_1588_PTP_GET_CAPS" ops is sent by the VF to request PTP capabilities and responded by the PF with capabilities enabled for that VF.

"VIRTCHNL_OP_1588_PTP_GET_TIME" ops is sent by the VF to request the current time of the PHC. The PF will respond by reading the device time and reporting it back to the VF.

---
 drivers/common/iavf/virtchnl.h | 62 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 60 insertions(+), 2 deletions(-)
drivers/common/iavf/virtchnl.h +60 -2
index 249ae6e..2d49f95 100644
@@ -159,6 +159,8 @@ enum virtchnl_ops {
 	VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 = 57,
 	VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2 = 58,
 	VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 = 59,
+	VIRTCHNL_OP_1588_PTP_GET_CAPS = 60,
+	VIRTCHNL_OP_1588_PTP_GET_TIME = 61,
 	VIRTCHNL_OP_GET_QOS_CAPS = 66,
 	VIRTCHNL_OP_CONFIG_QUEUE_TC_MAP = 67,
 	VIRTCHNL_OP_ENABLE_QUEUES_V2 = 107,
@@ -276,6 +278,10 @@ static inline const char *virtchnl_op_str(enum virtchnl_ops v_opcode)
 		return "VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2";
 	case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
 		return "VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2";
+	case VIRTCHNL_OP_1588_PTP_GET_CAPS:
+		return "VIRTCHNL_OP_1588_PTP_GET_CAPS";
+	case VIRTCHNL_OP_1588_PTP_GET_TIME:
+		return "VIRTCHNL_OP_1588_PTP_GET_TIME";
 	case VIRTCHNL_OP_MAX:
 		return "VIRTCHNL_OP_MAX";
 	default:
@@ -411,7 +417,7 @@ VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource);
 #define VIRTCHNL_VF_OFFLOAD_FDIR_PF		BIT(28)
 #define VIRTCHNL_VF_OFFLOAD_QOS		BIT(29)
 #define VIRTCHNL_VF_CAP_DCF			BIT(30)
-	/* BIT(31) is reserved */
+#define VIRTCHNL_VF_CAP_PTP			BIT(31)
 
 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \
 			       VIRTCHNL_VF_OFFLOAD_VLAN | \
@@ -498,6 +504,18 @@ enum virtchnl_rx_desc_id_bitmasks {
 	/* 22 through 63 are reserved */
 };
 
+/* virtchnl_rxq_info_flags
+ *
+ * Definition of bits in the flags field of the virtchnl_rxq_info structure.
+ */
+enum virtchnl_rxq_info_flags {
+	/* If the VIRTCHNL_PTP_RX_TSTAMP bit of the flag field is set, this is
+	 * a request to enable Rx timestamp. Other flag bits are currently
+	 * reserved and they may be extended in the future.
+	 */
+	VIRTCHNL_PTP_RX_TSTAMP = BIT(0),
+};
+
 /* VIRTCHNL_OP_CONFIG_RX_QUEUE
  * VF sends this message to set up parameters for one RX queue.
  * External data buffer contains one instance of virtchnl_rxq_info.
@@ -526,7 +544,8 @@ struct virtchnl_rxq_info {
 	 * with VIRTCHNL_RXDID_1_32B_BASE.
 	 */
 	u8 rxdid;
-	u8 pad1[2];
+	u8 flags; /* see virtchnl_rxq_info_flags */
+	u8 pad1;
 	u64 dma_ring_addr;
 
 	/* see enum virtchnl_rx_hsplit; deprecated with AVF 1.0 */
@@ -2004,6 +2023,39 @@ struct virtchnl_quanta_cfg {
 
 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_quanta_cfg);
 
+#define VIRTCHNL_1588_PTP_CAP_RX_TSTAMP		BIT(1)
+#define VIRTCHNL_1588_PTP_CAP_READ_PHC		BIT(2)
+
+struct virtchnl_phc_regs {
+	u32 clock_hi;
+	u32 clock_lo;
+	u8 pcie_region;
+	u8 rsvd[15];
+};
+
+VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_phc_regs);
+
+struct virtchnl_ptp_caps {
+	struct virtchnl_phc_regs phc_regs;
+	u32 caps;
+	s32 max_adj;
+	u8 tx_tstamp_idx;
+	u8 n_ext_ts;
+	u8 n_per_out;
+	u8 n_pins;
+	u8 tx_tstamp_format;
+	u8 rsvd[11];
+};
+
+VIRTCHNL_CHECK_STRUCT_LEN(48, virtchnl_ptp_caps);
+
+struct virtchnl_phc_time {
+	u64 time;
+	u8 rsvd[8];
+};
+
+VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_phc_time);
+
 /* Since VF messages are limited by u16 size, precalculate the maximum possible
  * values of nested elements in virtchnl structures that virtual channel can
  * possibly handle in a single message.
@@ -2321,6 +2373,12 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
 	case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2:
 		valid_len = sizeof(struct virtchnl_vlan_setting);
 		break;
+	case VIRTCHNL_OP_1588_PTP_GET_CAPS:
+		valid_len = sizeof(struct virtchnl_ptp_caps);
+		break;
+	case VIRTCHNL_OP_1588_PTP_GET_TIME:
+		valid_len = sizeof(struct virtchnl_phc_time);
+		break;
 	case VIRTCHNL_OP_ENABLE_QUEUES_V2:
 	case VIRTCHNL_OP_DISABLE_QUEUES_V2:
 		valid_len = sizeof(struct virtchnl_del_ena_dis_queues);
Signature · 1 line
2.9.5
author
#10 lore raw

PATCH v3 2/3 net/iavf: enable Rx timestamp on Flex Descriptor

In reply to Simei Su

Dump Rx timestamp value into dynamic mbuf field by flex descriptor. This feature is turned on by dev config "enable-rx-timestamp". Currently, it's only supported under scalar path.

---
 doc/guides/nics/features/iavf.ini       |  1 +
 doc/guides/rel_notes/release_22_07.rst  |  2 +-
 drivers/net/iavf/iavf.h                 |  5 ++
 drivers/net/iavf/iavf_ethdev.c          | 26 +++++++++++
 drivers/net/iavf/iavf_rxtx.c            | 59 +++++++++++++++++++++++
 drivers/net/iavf/iavf_rxtx.h            | 22 +++++++++
 drivers/net/iavf/iavf_rxtx_vec_common.h |  3 ++
 drivers/net/iavf/iavf_vchnl.c           | 83 ++++++++++++++++++++++++++++-----
 8 files changed, 189 insertions(+), 12 deletions(-)
doc/guides/nics/features/iavf.ini +1 -0
index 01f5142..5a0d9d8 100644
@@ -24,6 +24,7 @@ CRC offload          = Y
 VLAN offload         = Y
 L3 checksum offload  = P
 L4 checksum offload  = P
+Timestamp offload    = P
 Packet type parsing  = Y
 Rx descriptor status = Y
 Tx descriptor status = Y
doc/guides/rel_notes/release_22_07.rst +1 -1
index 90123bb..567f23d 100644
@@ -59,7 +59,7 @@ New Features
 
   * Added Tx QoS queue rate limitation support.
   * Added quanta size configuration support.
-
+  * Added ``DEV_RX_OFFLOAD_TIMESTAMP`` support.
 
 Removed Items
 -------------
drivers/net/iavf/iavf.h +5 -0
index c0a4a47..3255c93 100644
@@ -268,6 +268,8 @@ struct iavf_info {
 	struct iavf_tm_conf tm_conf;
 
 	struct rte_eth_dev *eth_dev;
+
+	uint32_t ptp_caps;
 };
 
 #define IAVF_MAX_PKT_TYPE 1024
@@ -312,6 +314,7 @@ struct iavf_adapter {
 	bool stopped;
 	uint16_t fdir_ref_cnt;
 	struct iavf_devargs devargs;
+	uint64_t phc_time;
 };
 
 /* IAVF_DEV_PRIVATE_TO */
@@ -476,4 +479,6 @@ int iavf_ipsec_crypto_request(struct iavf_adapter *adapter,
 		uint8_t *msg, size_t msg_len,
 		uint8_t *resp_msg, size_t resp_msg_len);
 extern const struct rte_tm_ops iavf_tm_ops;
+int iavf_get_ptp_cap(struct iavf_adapter *adapter);
+int iavf_get_phc_time(struct iavf_adapter *adapter);
 #endif /* _IAVF_ETHDEV_H_ */
drivers/net/iavf/iavf_ethdev.c +26 -0
index 7d093bd..89e4240 100644
@@ -36,6 +36,9 @@
 #define IAVF_PROTO_XTR_ARG         "proto_xtr"
 #define IAVF_QUANTA_SIZE_ARG       "quanta_size"
 
+uint64_t iavf_timestamp_dynflag;
+int iavf_timestamp_dynfield_offset = -1;
+
 static const char * const iavf_valid_args[] = {
 	IAVF_PROTO_XTR_ARG,
 	IAVF_QUANTA_SIZE_ARG,
@@ -687,6 +690,7 @@ iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
 	struct rte_eth_dev_data *dev_data = dev->data;
 	uint16_t buf_size, max_pkt_len;
 	uint32_t frame_size = dev->data->mtu + IAVF_ETH_OVERHEAD;
+	enum iavf_status err;
 
 	buf_size = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
 
@@ -705,6 +709,18 @@ iavf_init_rxq(struct rte_eth_dev *dev, struct iavf_rx_queue *rxq)
 		return -EINVAL;
 	}
 
+	if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
+		/* Register mbuf field and flag for Rx timestamp */
+		err = rte_mbuf_dyn_rx_timestamp_register(
+			&iavf_timestamp_dynfield_offset,
+			&iavf_timestamp_dynflag);
+		if (err) {
+			PMD_DRV_LOG(ERR,
+				    "Cannot register mbuf field/flag for timestamp");
+			return -EINVAL;
+		}
+	}
+
 	rxq->max_pkt_len = max_pkt_len;
 	if ((dev_data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) ||
 	    rxq->max_pkt_len > buf_size) {
@@ -947,6 +963,13 @@ iavf_dev_start(struct rte_eth_dev *dev)
 			return -1;
 		}
 
+	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP) {
+		if (iavf_get_ptp_cap(adapter)) {
+			PMD_INIT_LOG(ERR, "Failed to get ptp capability");
+			return -1;
+		}
+	}
+
 	if (iavf_init_queues(dev) != 0) {
 		PMD_DRV_LOG(ERR, "failed to do Queue init");
 		return -1;
@@ -1092,6 +1115,9 @@ iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_CRC)
 		dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
 
+	if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_CAP_PTP)
+		dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
+
 	if (iavf_ipsec_crypto_supported(adapter)) {
 		dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_SECURITY;
 		dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_SECURITY;
drivers/net/iavf/iavf_rxtx.c +59 -0

106 lines not on this page · raw message

drivers/net/iavf/iavf_rxtx.h +22 -0
index bf8aebb..37453c4 100644
@@ -72,6 +72,9 @@
 #define IAVF_TX_OFFLOAD_NOTSUP_MASK \
 		(RTE_MBUF_F_TX_OFFLOAD_MASK ^ IAVF_TX_OFFLOAD_MASK)
 
+extern uint64_t iavf_timestamp_dynflag;
+extern int iavf_timestamp_dynfield_offset;
+
 /**
  * Rx Flex Descriptors
  * These descriptors are used instead of the legacy version descriptors
@@ -219,6 +222,7 @@ struct iavf_rx_queue {
 		/* flexible descriptor metadata extraction offload flag */
 	struct iavf_rx_queue_stats stats;
 	uint64_t offloads;
+	uint32_t hw_register_set;
 };
 
 struct iavf_tx_entry {
@@ -778,6 +782,24 @@ void iavf_fdir_rx_proc_enable(struct iavf_adapter *ad, bool on)
 	}
 }
 
+static inline
+uint64_t iavf_tstamp_convert_32b_64b(uint64_t time, uint32_t in_timestamp)
+{
+	const uint64_t mask = 0xFFFFFFFF;
+	uint32_t delta;
+	uint64_t ns;
+
+	delta = (in_timestamp - (uint32_t)(time & mask));
+	if (delta > (mask / 2)) {
+		delta = ((uint32_t)(time & mask) - in_timestamp);
+		ns = time - delta;
+	} else {
+		ns = time + delta;
+	}
+
+	return ns;
+}
+
 #ifdef RTE_LIBRTE_IAVF_DEBUG_DUMP_DESC
 #define IAVF_DUMP_RX_DESC(rxq, desc, rx_id) \
 	iavf_dump_rx_descriptor(rxq, desc, rx_id)
drivers/net/iavf/iavf_rxtx_vec_common.h +3 -0
index 1fd37b7..a59cb2c 100644
@@ -231,6 +231,9 @@ iavf_rx_vec_queue_default(struct iavf_rx_queue *rxq)
 	if (rxq->proto_xtr != IAVF_PROTO_XTR_NONE)
 		return -1;
 
+	if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
+		return -1;
+
 	if (rxq->offloads & IAVF_RX_VECTOR_OFFLOAD)
 		return IAVF_VECTOR_OFFLOAD_PATH;
 
drivers/net/iavf/iavf_vchnl.c +72 -11

98 lines not on this page · raw message

Signature · 1 line
2.9.5
author
#11 lore raw

PATCH v3 3/3 net/iavf: improve performance of Rx timestamp offload

In reply to Simei Su

In this patch, We use CPU ticks instead of HW register to determine whether low 32 bits timestamp has turned over. It can avoid requesting register value frequently and improve receiving performance.

---
 drivers/net/iavf/iavf.h        |  1 +
 drivers/net/iavf/iavf_ethdev.c |  9 ++++++++
 drivers/net/iavf/iavf_rxtx.c   | 51 +++++++++++++++++++++++++++---------------
 drivers/net/iavf/iavf_rxtx.h   |  1 -
 4 files changed, 43 insertions(+), 19 deletions(-)
drivers/net/iavf/iavf.h +1 -0
index 3255c93..dd83567 100644
@@ -315,6 +315,7 @@ struct iavf_adapter {
 	uint16_t fdir_ref_cnt;
 	struct iavf_devargs devargs;
 	uint64_t phc_time;
+	uint64_t hw_time_update;
 };
 
 /* IAVF_DEV_PRIVATE_TO */
drivers/net/iavf/iavf_ethdev.c +9 -0
index 89e4240..d1a2b53 100644
@@ -1019,6 +1019,15 @@ iavf_dev_start(struct rte_eth_dev *dev)
 		goto err_mac;
 	}
 
+	if (dev->data->dev_conf.rxmode.offloads &
+	    RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
+		if (iavf_get_phc_time(adapter)) {
+			PMD_DRV_LOG(ERR, "get physical time failed");
+			goto err_mac;
+		}
+		adapter->hw_time_update = rte_get_timer_cycles() / (rte_get_timer_hz() / 1000);
+	}
+
 	return 0;
 
 err_mac:
drivers/net/iavf/iavf_rxtx.c +33 -18

96 lines not on this page · raw message

drivers/net/iavf/iavf_rxtx.h +0 -1
index 37453c4..642b9a7 100644
@@ -222,7 +222,6 @@ struct iavf_rx_queue {
 		/* flexible descriptor metadata extraction offload flag */
 	struct iavf_rx_queue_stats stats;
 	uint64_t offloads;
-	uint32_t hw_register_set;
 };
 
 struct iavf_tx_entry {
Signature · 1 line
2.9.5
#12 lore raw

Re: [PATCH v3 3/3] net/iavf: improve performance of Rx timestamp offload

28/04/2022 10:13, Simei Su:

Quoted 6 lines

In this patch, We use CPU ticks instead of HW register to determine whether low 32 bits timestamp has turned over. It can avoid requesting register value frequently and improve receiving performance.

It seems you've lost original authorship.
The patch is implicitly assigned to Simei Su.
I'll restore it to Wenjun Wu.

Acked-by on the v3 series Applied
#13 lore raw
In reply to Simei Su
Quoted 39 lines

-----Original Message-----
From: Su, Simei <[email protected]>
Sent: Thursday, April 28, 2022 4:14 PM
To: Zhang, Qi Z <[email protected]>; Yang, Qiming <[email protected]>
Cc: [email protected]; Wu, Wenjun1 <[email protected]>; Su, Simei <[email protected]>
Subject: [PATCH v3 0/3] net/iavf: support Rx timestamp on flex descriptor

[PATCH v3 1/3] add related ops and structure for Rx timestamp in virtual channel.
[PATCH v3 2/3] add support for Rx timestamp on flex descriptor in driver. [PATCH v3 3/3] improve performance with Rx timestamp enabled.

v3:
* Rebase code.
* Fix compile warning.

v2:
* Add release notes and doc update.

Simei Su (3):
common/iavf: support Rx timestamp in virtual channel net/iavf: enable Rx timestamp on Flex Descriptor net/iavf: improve performance of Rx timestamp offload

 doc/guides/nics/features/iavf.ini       |  1 +
 doc/guides/rel_notes/release_22_07.rst  |  2 +-
 drivers/common/iavf/virtchnl.h          | 62 +++++++++++++++++++++++-
 drivers/net/iavf/iavf.h                 |  6 +++
 drivers/net/iavf/iavf_ethdev.c          | 35 ++++++++++++++
 drivers/net/iavf/iavf_rxtx.c            | 74 +++++++++++++++++++++++++++++
 drivers/net/iavf/iavf_rxtx.h            | 21 +++++++++
 drivers/net/iavf/iavf_rxtx_vec_common.h |  3 ++
 drivers/net/iavf/iavf_vchnl.c           | 83 ++++++++++++++++++++++++++++----
-
 9 files changed, 273 insertions(+), 14 deletions(-)
Quoted 2 lines

--
2.9.5

Applied to dpdk-next-net-intel.

Thanks
Qi