Skip to contentSkip to conversation

Support PTP for hns3 PMD

PATCH Superseded Min Hu (Connor) 3 participants 17 messages Mar 26, 2021 – Apr 1, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Support PTP for hns3 PMD

This set includes two patches, one patch is to fix cyclomatic complexity, the other patch is to support PTP, but depends on the first patch. So the two forms one set of patches.

Min Hu (Connor) (2):
net/hns3: fix code check warning
net/hns3: support IEEE 1588 PTP

 doc/guides/nics/features/hns3.ini |   2 +
 doc/guides/nics/hns3.rst          |   1 +
 drivers/net/hns3/hns3_cmd.h       |  33 +++++
 drivers/net/hns3/hns3_ethdev.c    | 120 ++++++++++++----
 drivers/net/hns3/hns3_ethdev.h    |  25 ++++
 drivers/net/hns3/hns3_ptp.c       | 294 ++++++++++++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_regs.h      |  25 ++++
 drivers/net/hns3/hns3_rxtx.c      |  56 +++++++-
 drivers/net/hns3/hns3_rxtx.h      |  12 ++
 drivers/net/hns3/hns3_rxtx_vec.c  |  19 ++-
 drivers/net/hns3/meson.build      |   3 +-
 11 files changed, 553 insertions(+), 37 deletions(-)
 create mode 100644 drivers/net/hns3/hns3_ptp.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 net/hns3: fix code check warning

This patch fixed cyclomatic complexity about MTU
in device configure process.

Fixes 1f5ca0b460cd ("net/hns3: support some device operations")
---
 drivers/net/hns3/hns3_ethdev.c | 61 +++++++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 24 deletions(-)
drivers/net/hns3/hns3_ethdev.c +37 -24
index b7bfac8..b985447 100644
@@ -2373,6 +2373,40 @@ hns3_init_ring_with_vector(struct hns3_hw *hw)
 }
 
 static int
+hns3_refresh_mtu(struct rte_eth_dev *dev, struct rte_eth_conf *conf)
+{
+	struct hns3_adapter *hns = dev->data->dev_private;
+	struct hns3_hw *hw = &hns->hw;
+	uint32_t max_rx_pkt_len;
+	uint16_t mtu;
+	int ret;
+
+	if (!(conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME))
+		return 0;
+
+	/*
+	 * If jumbo frames are enabled, MTU needs to be refreshed
+	 * according to the maximum RX packet length.
+	 */
+	max_rx_pkt_len = conf->rxmode.max_rx_pkt_len;
+	if (max_rx_pkt_len > HNS3_MAX_FRAME_LEN ||
+	    max_rx_pkt_len <= HNS3_DEFAULT_FRAME_LEN) {
+		hns3_err(hw, "maximum Rx packet length must be greater than %u "
+			 "and no more than %u when jumbo frame enabled.",
+			 (uint16_t)HNS3_DEFAULT_FRAME_LEN,
+			 (uint16_t)HNS3_MAX_FRAME_LEN);
+		return -EINVAL;
+	}
+
+	mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(max_rx_pkt_len);
+	ret = hns3_dev_mtu_set(dev, mtu);
+	if (ret)
+		return ret;
+	dev->data->mtu = mtu;
+
+	return 0;
+}
+static int
 hns3_dev_configure(struct rte_eth_dev *dev)
 {
 	struct hns3_adapter *hns = dev->data->dev_private;
@@ -2382,8 +2416,6 @@ hns3_dev_configure(struct rte_eth_dev *dev)
 	uint16_t nb_rx_q = dev->data->nb_rx_queues;
 	uint16_t nb_tx_q = dev->data->nb_tx_queues;
 	struct rte_eth_rss_conf rss_conf;
-	uint32_t max_rx_pkt_len;
-	uint16_t mtu;
 	bool gro_en;
 	int ret;
 
@@ -2431,28 +2463,9 @@ hns3_dev_configure(struct rte_eth_dev *dev)
 			goto cfg_err;
 	}
 
-	/*
-	 * If jumbo frames are enabled, MTU needs to be refreshed
-	 * according to the maximum RX packet length.
-	 */
-	if (conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
-		max_rx_pkt_len = conf->rxmode.max_rx_pkt_len;
-		if (max_rx_pkt_len > HNS3_MAX_FRAME_LEN ||
-		    max_rx_pkt_len <= HNS3_DEFAULT_FRAME_LEN) {
-			hns3_err(hw, "maximum Rx packet length must be greater "
-				 "than %u and less than %u when jumbo frame enabled.",
-				 (uint16_t)HNS3_DEFAULT_FRAME_LEN,
-				 (uint16_t)HNS3_MAX_FRAME_LEN);
-			ret = -EINVAL;
-			goto cfg_err;
-		}
-
-		mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(max_rx_pkt_len);
-		ret = hns3_dev_mtu_set(dev, mtu);
-		if (ret)
-			goto cfg_err;
-		dev->data->mtu = mtu;
-	}
+	ret = hns3_refresh_mtu(dev, conf);
+	if (ret)
+		goto cfg_err;
 
 	ret = hns3_dev_configure_vlan(dev);
 	if (ret)
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/2 net/hns3: support IEEE 1588 PTP

In reply to Min Hu (Connor)

Add hns3 support for new ethdev APIs to enable and read IEEE1588/ 802.1AS PTP timestamps.

---
 doc/guides/nics/features/hns3.ini |   2 +
 doc/guides/nics/hns3.rst          |   1 +
 drivers/net/hns3/hns3_cmd.h       |  33 +++++
 drivers/net/hns3/hns3_ethdev.c    |  59 +++++++-
 drivers/net/hns3/hns3_ethdev.h    |  25 ++++
 drivers/net/hns3/hns3_ptp.c       | 294 ++++++++++++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_regs.h      |  25 ++++
 drivers/net/hns3/hns3_rxtx.c      |  56 +++++++-
 drivers/net/hns3/hns3_rxtx.h      |  12 ++
 drivers/net/hns3/hns3_rxtx_vec.c  |  19 ++-
 drivers/net/hns3/meson.build      |   3 +-
 11 files changed, 516 insertions(+), 13 deletions(-)
 create mode 100644 drivers/net/hns3/hns3_ptp.c
doc/guides/nics/features/hns3.ini +2 -0
index 3988be4..502bfe7 100644
@@ -43,6 +43,8 @@ Stats per queue      = Y
 FW version           = Y
 Registers dump       = Y
 Module EEPROM dump   = Y
+Timesync             = Y
+Timestamp offload    = Y
 Multiprocess aware   = Y
 Linux                = Y
 ARMv8                = Y
doc/guides/nics/hns3.rst +1 -0
index ccd2f6f..3366562 100644
@@ -37,6 +37,7 @@ Features of the HNS3 PMD are:
 - MTU update
 - NUMA support
 - Generic flow API
+- IEEE1588/802.1AS timestamping
 
 Prerequisites
 -------------
drivers/net/hns3/hns3_cmd.h +33 -0
index e704d0c..abc853b 100644
@@ -123,6 +123,12 @@ enum hns3_opcode_type {
 	HNS3_OPC_CLEAR_MAC_TNL_INT      = 0x0312,
 	HNS3_OPC_CONFIG_FEC_MODE        = 0x031A,
 
+#ifdef RTE_LIBRTE_IEEE1588
+	/* PTP command */
+	HNS3_OPC_PTP_INT_EN             = 0x0501,
+	HNS3_OPC_CFG_PTP_MODE           = 0x0507,
+#endif
+
 	/* PFC/Pause commands */
 	HNS3_OPC_CFG_MAC_PAUSE_EN       = 0x0701,
 	HNS3_OPC_CFG_PFC_PAUSE_EN       = 0x0702,
@@ -969,6 +975,33 @@ struct hns3_query_ssu_cmd {
 	uint32_t oq_drop_cnt;
 	uint32_t rev1[2];
 };
+#ifdef RTE_LIBRTE_IEEE1588
+#define HNS3_PTP_ENABLE_B               0
+#define HNS3_PTP_TX_ENABLE_B            1
+#define HNS3_PTP_RX_ENABLE_B            2
+
+#define HNS3_PTP_TYPE_S                 0
+#define HNS3_PTP_TYPE_M                (0x3 << HNS3_PTP_TYPE_S)
+
+#define ALL_PTP_V2_TYPE                 0xF
+#define HNS3_PTP_MESSAGE_TYPE_S         0
+#define HNS3_PTP_MESSAGE_TYPE_M        (0xF << HNS3_PTP_MESSAGE_TYPE_S)
+
+#define PTP_TYPE_L2_V2_TYPE             0
+
+struct hns3_ptp_mode_cfg_cmd {
+	uint8_t enable;
+	uint8_t ptp_type;
+	uint8_t v2_message_type_1;
+	uint8_t v2_message_type_0;
+	uint8_t rsv[20];
+};
+
+struct hns3_ptp_int_cmd {
+	uint8_t int_en;
+	uint8_t rsvd[23];
+};
+#endif
 
 #define HNS3_MAX_TQP_NUM_HIP08_PF	64
 #define HNS3_DEFAULT_TX_BUF		0x4000    /* 16k  bytes */
drivers/net/hns3/hns3_ethdev.c +58 -1

116 lines not on this page · raw message

drivers/net/hns3/hns3_ethdev.h +25 -0
index f69e2d8..4ce192c 100644
@@ -731,6 +731,13 @@ struct hns3_pf {
 	bool support_sfp_query;
 	uint32_t fec_mode; /* current FEC mode for ethdev */
 
+#ifdef RTE_LIBRTE_IEEE1588
+	bool ptp_enable;
+
+	/* Stores timestamp of last received packet on dev */
+	uint64_t rx_timestamp;
+#endif
+
 	struct hns3_vtag_cfg vtag_config;
 	LIST_HEAD(vlan_tbl, hns3_user_vlan_table) vlan_list;
 
@@ -982,6 +989,24 @@ void hns3vf_update_link_status(struct hns3_hw *hw, uint8_t link_status,
 			  uint32_t link_speed, uint8_t link_duplex);
 void hns3_parse_devargs(struct rte_eth_dev *dev);
 
+#ifdef RTE_LIBRTE_IEEE1588
+int hns3_restore_ptp(struct hns3_adapter *hns);
+int hns3_mbuf_dyn_rx_timestamp_register(struct rte_eth_dev *dev,
+				    struct rte_eth_conf *conf);
+int hns3_ptp_init(struct hns3_hw *hw);
+int hns3_timesync_enable(struct rte_eth_dev *dev);
+int hns3_timesync_disable(struct rte_eth_dev *dev);
+int hns3_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
+				struct timespec *timestamp,
+				uint32_t flags __rte_unused);
+int hns3_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
+				struct timespec *timestamp);
+int hns3_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts);
+int hns3_timesync_write_time(struct rte_eth_dev *dev,
+			const struct timespec *ts);
+int hns3_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
+#endif
+
 static inline bool
 is_reset_pending(struct hns3_adapter *hns)
 {
drivers/net/hns3/hns3_ptp.c new file +294 -0

294 lines not on this page · raw message

drivers/net/hns3/hns3_regs.h +25 -0
index e141fe1..58a20ca 100644
@@ -121,6 +121,31 @@
 #define HNS3_TQP_INTR_RL_DEFAULT		0
 #define HNS3_TQP_INTR_QL_DEFAULT		0
 
+#ifdef RTE_LIBRTE_IEEE1588
+/* Register bit for 1588 event */
+#define HNS3_VECTOR0_1588_INT_B	                0
+
+#define HNS3_PTP_BASE_ADDRESS			0x29000
+
+#define HNS3_TX_1588_SEQID_BACK			(HNS3_PTP_BASE_ADDRESS + 0x0)
+#define HNS3_TX_1588_TSP_BACK_0			(HNS3_PTP_BASE_ADDRESS + 0x4)
+#define HNS3_TX_1588_TSP_BACK_1			(HNS3_PTP_BASE_ADDRESS + 0x8)
+#define HNS3_TX_1588_TSP_BACK_2			(HNS3_PTP_BASE_ADDRESS + 0xc)
+
+#define HNS3_TX_1588_BACK_TSP_CNT		(HNS3_PTP_BASE_ADDRESS + 0x30)
+
+#define HNS3_CFG_TIME_SYNC_H			(HNS3_PTP_BASE_ADDRESS + 0x50)
+#define HNS3_CFG_TIME_SYNC_M			(HNS3_PTP_BASE_ADDRESS + 0x54)
+#define HNS3_CFG_TIME_SYNC_L			(HNS3_PTP_BASE_ADDRESS + 0x58)
+#define HNS3_CFG_TIME_SYNC_RDY			(HNS3_PTP_BASE_ADDRESS + 0x5c)
+
+#define HNS3_CFG_TIME_CYC_EN			(HNS3_PTP_BASE_ADDRESS + 0x70)
+
+#define HNS3_CURR_TIME_OUT_H			(HNS3_PTP_BASE_ADDRESS + 0x74)
+#define HNS3_CURR_TIME_OUT_L			(HNS3_PTP_BASE_ADDRESS + 0x78)
+#define HNS3_CURR_TIME_OUT_NS			(HNS3_PTP_BASE_ADDRESS + 0x7c)
+#endif
+
 /* gl_usec convert to hardware count, as writing each 1 represents 2us */
 #define HNS3_GL_USEC_TO_REG(gl_usec)		((gl_usec) >> 1)
 /* rl_usec convert to hardware count, as writing each 1 represents 4us */
drivers/net/hns3/hns3_rxtx.c +52 -4

109 lines not on this page · raw message

drivers/net/hns3/hns3_rxtx.h +12 -0
index f9b3048..74e5407 100644
@@ -106,6 +106,8 @@
 #define HNS3_RXD_L3L4P_B			11
 #define HNS3_RXD_TSIND_S			12
 #define HNS3_RXD_TSIND_M			(0x7 << HNS3_RXD_TSIND_S)
+
+#define HNS3_RXD_TS_VLD_B			14
 #define HNS3_RXD_LKBK_B				15
 #define HNS3_RXD_GRO_SIZE_S			16
 #define HNS3_RXD_GRO_SIZE_M			(0x3fff << HNS3_RXD_GRO_SIZE_S)
@@ -200,6 +202,11 @@ enum hns3_pkt_tun_type {
 struct hns3_desc {
 	union {
 		uint64_t addr;
+
+#ifdef RTE_LIBRTE_IEEE1588
+		uint64_t timestamp;
+#endif
+
 		struct {
 			uint32_t addr0;
 			uint32_t addr1;
@@ -518,6 +525,11 @@ enum hns3_cksum_status {
 	HNS3_OUTER_L4_CKSUM_ERR = 8
 };
 
+#ifdef RTE_LIBRTE_IEEE1588
+extern uint64_t hns3_timestamp_rx_dynflag;
+extern int hns3_timestamp_dynfield_offset;
+#endif
+
 static inline int
 hns3_handle_bdinfo(struct hns3_rx_queue *rxq, struct rte_mbuf *rxm,
 		   uint32_t bd_base_info, uint32_t l234_info,
drivers/net/hns3/hns3_rxtx_vec.c +12 -7
index 2bc4372..4584d8a 100644
@@ -18,6 +18,12 @@ hns3_tx_check_vec_support(struct rte_eth_dev *dev)
 {
 	struct rte_eth_txmode *txmode = &dev->data->dev_conf.txmode;
 
+#ifdef RTE_LIBRTE_IEEE1588
+	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	if (hns3_dev_ptp_supported(hw))
+		return -ENOTSUP;
+#endif
+
 	/* Only support DEV_TX_OFFLOAD_MBUF_FAST_FREE */
 	if (txmode->offloads != DEV_TX_OFFLOAD_MBUF_FAST_FREE)
 		return -ENOTSUP;
@@ -167,7 +173,6 @@ hns3_rxq_vec_setup(struct hns3_rx_queue *rxq)
 	memset(rxq->offset_table, 0, sizeof(rxq->offset_table));
 }
 
-#ifndef RTE_LIBRTE_IEEE1588
 static int
 hns3_rxq_vec_check(struct hns3_rx_queue *rxq, void *arg)
 {
@@ -183,17 +188,21 @@ hns3_rxq_vec_check(struct hns3_rx_queue *rxq, void *arg)
 	RTE_SET_USED(arg);
 	return 0;
 }
-#endif
 
 int
 hns3_rx_check_vec_support(struct rte_eth_dev *dev)
 {
-#ifndef RTE_LIBRTE_IEEE1588
 	struct rte_fdir_conf *fconf = &dev->data->dev_conf.fdir_conf;
 	struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
 	uint64_t offloads_mask = DEV_RX_OFFLOAD_TCP_LRO |
 				 DEV_RX_OFFLOAD_VLAN;
 
+#ifdef RTE_LIBRTE_IEEE1588
+	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	if (hns3_dev_ptp_supported(hw))
+		return -ENOTSUP;
+#endif
+
 	if (dev->data->scattered_rx)
 		return -ENOTSUP;
 
@@ -207,8 +216,4 @@ hns3_rx_check_vec_support(struct rte_eth_dev *dev)
 		return -ENOTSUP;
 
 	return 0;
-#else
-	RTE_SET_USED(dev);
-	return -ENOTSUP;
-#endif
 }
drivers/net/hns3/meson.build +2 -1
index f6aac69..6d78c33 100644
@@ -26,7 +26,8 @@ sources = files('hns3_cmd.c',
 	'hns3_rxtx.c',
 	'hns3_stats.c',
 	'hns3_mp.c',
-	'hns3_tm.c')
+	'hns3_tm.c',
+	'hns3_ptp.c')
 
 deps += ['hash']
 
Signature · 1 line
2.7.4
#3 lore raw

Re: [dpdk-dev] [PATCH 2/2] net/hns3: support IEEE 1588 PTP

Quoted 49 lines · Min Hu (Connor)

Add hns3 support for new ethdev APIs to enable and read IEEE1588/ 802.1AS PTP timestamps.

---
  doc/guides/nics/features/hns3.ini |   2 +
  doc/guides/nics/hns3.rst          |   1 +
  drivers/net/hns3/hns3_cmd.h       |  33 +++++
  drivers/net/hns3/hns3_ethdev.c    |  59 +++++++-
  drivers/net/hns3/hns3_ethdev.h    |  25 ++++
  drivers/net/hns3/hns3_ptp.c       | 294 ++++++++++++++++++++++++++++++++++++++
  drivers/net/hns3/hns3_regs.h      |  25 ++++
  drivers/net/hns3/hns3_rxtx.c      |  56 +++++++-
  drivers/net/hns3/hns3_rxtx.h      |  12 ++
  drivers/net/hns3/hns3_rxtx_vec.c  |  19 ++-
  drivers/net/hns3/meson.build      |   3 +-
  11 files changed, 516 insertions(+), 13 deletions(-)

create mode 100644 drivers/net/hns3/hns3_ptp.c

doc/guides/nics/features/hns3.ini +2 -0
index 3988be4..502bfe7 100644
@@ -43,6 +43,8 @@ Stats per queue      = Y
  FW version           = Y
  Registers dump       = Y
  Module EEPROM dump   = Y
+Timesync             = Y
+Timestamp offload    = Y
  Multiprocess aware   = Y
  Linux                = Y
  ARMv8                = Y
doc/guides/nics/hns3.rst +1 -0
index ccd2f6f..3366562 100644
@@ -37,6 +37,7 @@ Features of the HNS3 PMD are:
  - MTU update
  - NUMA support
  - Generic flow API
+- IEEE1588/802.1AS timestamping
 
  Prerequisites
  -------------
drivers/net/hns3/hns3_cmd.h +0 -0
index e704d0c..abc853b 100644

drivers/net/hns3/hns3_cmd.h enum hns3_opcode_type { · line 131

Quoted 9 lines
drivers/net/hns3/hns3_cmd.h +6 -0
@@ -123,6 +123,12 @@ enum hns3_opcode_type {
  	HNS3_OPC_CLEAR_MAC_TNL_INT      = 0x0312,
  	HNS3_OPC_CONFIG_FEC_MODE        = 0x031A,
 
+#ifdef RTE_LIBRTE_IEEE1588
+	/* PTP command */
+	HNS3_OPC_PTP_INT_EN             = 0x0501,
+	HNS3_OPC_CFG_PTP_MODE           = 0x0507,
+#endif
+

Hi Connor,

Does it needs to be a compile time configuration? What happens if it is always enabled, or controlled by device argument?

#4 lore raw

Re: [dpdk-dev] [PATCH 2/2] net/hns3: support IEEE 1588 PTP

Quoted 61 lines · Ferruh Yigit
Quoted 49 lines · Min Hu (Connor)

Add hns3 support for new ethdev APIs to enable and read IEEE1588/ 802.1AS PTP timestamps.

---
  doc/guides/nics/features/hns3.ini |   2 + doc/guides/nics/hns3.rst          |   1 + drivers/net/hns3/hns3_cmd.h       |  33 +++++ drivers/net/hns3/hns3_ethdev.c    |  59 +++++++- drivers/net/hns3/hns3_ethdev.h    |  25 ++++ drivers/net/hns3/hns3_ptp.c       | 294
++++++++++++++++++++++++++++++++++++++

  drivers/net/hns3/hns3_regs.h      |  25 ++++
  drivers/net/hns3/hns3_rxtx.c      |  56 +++++++-
  drivers/net/hns3/hns3_rxtx.h      |  12 ++
  drivers/net/hns3/hns3_rxtx_vec.c  |  19 ++-
  drivers/net/hns3/meson.build      |   3 +-
  11 files changed, 516 insertions(+), 13 deletions(-)

  create mode 100644 drivers/net/hns3/hns3_ptp.c

doc/guides/nics/features/hns3.ini +0 -0
index 3988be4..502bfe7 100644
@@ -43,6 +43,8 @@ Stats per queue      = Y

  FW version           = Y
  Registers dump       = Y
  Module EEPROM dump   = Y

doc/guides/nics/features/hns3.ini +2 -0
+Timesync             = Y
+Timestamp offload    = Y

  Multiprocess aware   = Y
  Linux                = Y
  ARMv8                = Y

doc/guides/nics/hns3.rst +0 -0
index ccd2f6f..3366562 100644
@@ -37,6 +37,7 @@ Features of the HNS3 PMD are:

  - MTU update
  - NUMA support
  - Generic flow API
+- IEEE1588/802.1AS timestamping
  Prerequisites
  -------------

drivers/net/hns3/hns3_cmd.h +0 -0
index e704d0c..abc853b 100644

drivers/net/hns3/hns3_cmd.h enum hns3_opcode_type { · line 130

Quoted 8 lines
drivers/net/hns3/hns3_cmd.h +6 -0
@@ -123,6 +123,12 @@ enum hns3_opcode_type {
       HNS3_OPC_CLEAR_MAC_TNL_INT      = 0x0312,
       HNS3_OPC_CONFIG_FEC_MODE        = 0x031A,
+#ifdef RTE_LIBRTE_IEEE1588
+    /* PTP command */
+    HNS3_OPC_PTP_INT_EN             = 0x0501,
+    HNS3_OPC_CFG_PTP_MODE           = 0x0507,
+#endif
+

Hi Connor,

Quoted 2 lines

Does it needs to be a compile time configuration? What happens if it is always enabled, or controlled by device argument? .

Hi Ferruh,
Firstly the "RTE_LIBRTE_IEEE1588" origins from the config file in DPDK.
Almost every nic driver use this macro in compile time.
For me, I think using this macro give one option for users to
decide if his APPs contains this module. For example, in loT field,
some microprocessor has small memory or small disk, So the APPs should be as small as possible. So, if user does not need "PTP", the APPs no need to contain it.
Well, another top, if is always enabled, for HNS3 PMD, it will
work well for our nic. If user want to use "PTP", just call API. If user
does not use it, it also doesn't matter. But we advise that if user
don't need this function, just turn it off.
Thanks.

#5 lore raw

Re: [dpdk-dev] [PATCH 2/2] net/hns3: support IEEE 1588 PTP

31/03/2021 04:35, Min Hu (Connor):

Quoted 23 lines · Ferruh Yigit
Quoted 19 lines · Min Hu (Connor)
Quoted 7 lines

Add hns3 support for new ethdev APIs to enable and read IEEE1588/ 802.1AS PTP timestamps.

drivers/net/hns3/hns3_cmd.h enum hns3_opcode_type { · line 130

Quoted 8 lines
drivers/net/hns3/hns3_cmd.h +6 -0
@@ -123,6 +123,12 @@ enum hns3_opcode_type {
      HNS3_OPC_CLEAR_MAC_TNL_INT      = 0x0312,
      HNS3_OPC_CONFIG_FEC_MODE        = 0x031A,
+#ifdef RTE_LIBRTE_IEEE1588
+    /* PTP command */
+    HNS3_OPC_PTP_INT_EN             = 0x0501,
+    HNS3_OPC_CFG_PTP_MODE           = 0x0507,
+#endif
+

Hi Connor,

Quoted 3 lines

Does it needs to be a compile time configuration? What happens if it is always enabled, or controlled by device argument?
.

Quoted 13 lines

Hi Ferruh,
Firstly the "RTE_LIBRTE_IEEE1588" origins from the config file in DPDK.
Almost every nic driver use this macro in compile time.
For me, I think using this macro give one option for users to
decide if his APPs contains this module. For example, in loT field, some microprocessor has small memory or small disk, So the APPs should be as small as possible. So, if user does not need "PTP", the APPs no need to contain it.
Well, another top, if is always enabled, for HNS3 PMD, it will
work well for our nic. If user want to use "PTP", just call API. If user does not use it, it also doesn't matter. But we advise that if user don't need this function, just turn it off.
Thanks.

Disabling at compile-time does not reduce the footprint significantly. RTE_LIBRTE_IEEE1588 should disappear, so I advise not using it in new code. Instead, you could enable/disable at runtime if needed.

#6 lore raw

Re: [dpdk-dev] [PATCH 2/2] net/hns3: support IEEE 1588 PTP

Quoted 38 lines · Thomas Monjalon

31/03/2021 04:35, Min Hu (Connor):

Quoted 23 lines · Ferruh Yigit
Quoted 19 lines · Min Hu (Connor)
Quoted 7 lines

Add hns3 support for new ethdev APIs to enable and read IEEE1588/ 802.1AS PTP timestamps.

drivers/net/hns3/hns3_cmd.h enum hns3_opcode_type { · line 130

Quoted 8 lines
drivers/net/hns3/hns3_cmd.h +6 -0
@@ -123,6 +123,12 @@ enum hns3_opcode_type {
       HNS3_OPC_CLEAR_MAC_TNL_INT      = 0x0312,
       HNS3_OPC_CONFIG_FEC_MODE        = 0x031A,
+#ifdef RTE_LIBRTE_IEEE1588
+    /* PTP command */
+    HNS3_OPC_PTP_INT_EN             = 0x0501,
+    HNS3_OPC_CFG_PTP_MODE           = 0x0507,
+#endif
+

Hi Connor,

Quoted 3 lines

Does it needs to be a compile time configuration? What happens if it is always enabled, or controlled by device argument?
.

Quoted 13 lines

Hi Ferruh,
Firstly the "RTE_LIBRTE_IEEE1588" origins from the config file in DPDK.
Almost every nic driver use this macro in compile time.
For me, I think using this macro give one option for users to
decide if his APPs contains this module. For example, in loT field, some microprocessor has small memory or small disk, So the APPs should be as small as possible. So, if user does not need "PTP", the APPs no need to contain it.
Well, another top, if is always enabled, for HNS3 PMD, it will
work well for our nic. If user want to use "PTP", just call API. If user does not use it, it also doesn't matter. But we advise that if user don't need this function, just turn it off.
Thanks.

Quoted 4 lines

Disabling at compile-time does not reduce the footprint significantly. RTE_LIBRTE_IEEE1588 should disappear, so I advise not using it in new code. Instead, you could enable/disable at runtime if needed.

I am aware that 'RTE_LIBRTE_IEEE1588' already exists and used by some drivers, but as you said they are from times we had a config option for it, for the new support I believe it is better to have runtime configuration.

And I agree with Thomas that it shouldn't increase the footprint much to always compile the support in, if you have numbers please share.

#7 lore raw

Re: [dpdk-dev] [PATCH 2/2] net/hns3: support IEEE 1588 PTP

Quoted 39 lines · Ferruh Yigit
Quoted 38 lines · Thomas Monjalon

31/03/2021 04:35, Min Hu (Connor):

Quoted 36 lines · Ferruh Yigit
Quoted 19 lines · Min Hu (Connor)
Quoted 7 lines

Add hns3 support for new ethdev APIs to enable and read IEEE1588/ 802.1AS PTP timestamps.

drivers/net/hns3/hns3_cmd.h enum hns3_opcode_type { · line 130

Quoted 8 lines
drivers/net/hns3/hns3_cmd.h +6 -0
@@ -123,6 +123,12 @@ enum hns3_opcode_type {
        HNS3_OPC_CLEAR_MAC_TNL_INT      = 0x0312,
        HNS3_OPC_CONFIG_FEC_MODE        = 0x031A,
+#ifdef RTE_LIBRTE_IEEE1588
+    /* PTP command */
+    HNS3_OPC_PTP_INT_EN             = 0x0501,
+    HNS3_OPC_CFG_PTP_MODE           = 0x0507,
+#endif
+

Hi Connor,

Quoted 3 lines

Does it needs to be a compile time configuration? What happens if it is always enabled, or controlled by device argument?
.

Hi Ferruh,
    Firstly the "RTE_LIBRTE_IEEE1588" origins from the config file in DPDK. Almost every nic driver use this macro in compile time.
    For me, I think using this macro give one option for users to decide if his APPs contains this module. For example, in loT field, some microprocessor has small memory or small disk, So the APPs should be as small as possible. So, if user does not need "PTP", the APPs no need to contain it.
    Well, another top, if is always enabled, for HNS3 PMD, it will work well for our nic. If user want to use "PTP", just call API. If user does not use it, it also doesn't matter. But we advise that if user don't need this function, just turn it off.
    Thanks.

Quoted 9 lines
Quoted 4 lines

Disabling at compile-time does not reduce the footprint significantly. RTE_LIBRTE_IEEE1588 should disappear, so I advise not using it in new code. Instead, you could enable/disable at runtime if needed.

I am aware that 'RTE_LIBRTE_IEEE1588' already exists and used by some drivers, but as you said they are from times we had a config option for it, for the new support I believe it is better to have runtime configuration.

And I agree with Thomas that it shouldn't increase the footprint much to always compile the support in, if you have numbers please share.

Well, thanks Thomas, Ferruh,
If there is no help to reduce the footprint significantly, I agree to
delete "RTE_LIBRTE_IEEE1588". As for runtime config, there is no need to
enable or disable PTP. Because We support the function, if user want to use it, just call related APIs, if not, don't use it.

So, I will delete the "RTE_LIBRTE_IEEE1588" in v3, what's your opinion? .

#8 lore raw

Re: [dpdk-dev] [PATCH 2/2] net/hns3: support IEEE 1588 PTP

In reply to Min Hu (Connor)
Quoted 4 lines · Min Hu (Connor)

Add hns3 support for new ethdev APIs to enable and read IEEE1588/ 802.1AS PTP timestamps.

Quoted 12 lines
---
  doc/guides/nics/features/hns3.ini |   2 +
  doc/guides/nics/hns3.rst          |   1 +
  drivers/net/hns3/hns3_cmd.h       |  33 +++++
  drivers/net/hns3/hns3_ethdev.c    |  59 +++++++-
  drivers/net/hns3/hns3_ethdev.h    |  25 ++++
  drivers/net/hns3/hns3_ptp.c       | 294 ++++++++++++++++++++++++++++++++++++++
  drivers/net/hns3/hns3_regs.h      |  25 ++++
  drivers/net/hns3/hns3_rxtx.c      |  56 +++++++-
  drivers/net/hns3/hns3_rxtx.h      |  12 ++
  drivers/net/hns3/hns3_rxtx_vec.c  |  19 ++-
  drivers/net/hns3/meson.build      |   3 +-

Can you please update release notes too?

#9 lore raw

Re: [dpdk-dev] [PATCH 2/2] net/hns3: support IEEE 1588 PTP

Quoted 19 lines · Ferruh Yigit
Quoted 12 lines · Min Hu (Connor)

Add hns3 support for new ethdev APIs to enable and read IEEE1588/ 802.1AS PTP timestamps.

---
  doc/guides/nics/features/hns3.ini |   2 + doc/guides/nics/hns3.rst          |   1 + drivers/net/hns3/hns3_cmd.h       |  33 +++++ drivers/net/hns3/hns3_ethdev.c    |  59 +++++++- drivers/net/hns3/hns3_ethdev.h    |  25 ++++ drivers/net/hns3/hns3_ptp.c       | 294
++++++++++++++++++++++++++++++++++++++

Quoted 5 lines
  drivers/net/hns3/hns3_regs.h      |  25 ++++
  drivers/net/hns3/hns3_rxtx.c      |  56 +++++++-
  drivers/net/hns3/hns3_rxtx.h      |  12 ++

  drivers/net/hns3/hns3_rxtx_vec.c  |  19 ++-
  drivers/net/hns3/meson.build      |   3 +-

Quoted 2 lines

Can you please update release notes too?

Will update doc/guides/rel_notes/release_21_05.rst in v2
Thanks

Quoted 1 line

.

#10 lore raw

v2 cover Support PTP for hns3 PMD

In reply to Min Hu (Connor)

This set includes two patches, one patch is to fix cyclomatic complexity, the other patch is to support PTP, but depends on the first patch. So the two forms one set of patches.

Min Hu (Connor) (2):
net/hns3: fix code check warning
net/hns3: support IEEE 1588 PTP

 doc/guides/nics/features/hns3.ini      |   2 +
 doc/guides/nics/hns3.rst               |   1 +
 doc/guides/rel_notes/release_21_05.rst |   1 +
 drivers/net/hns3/hns3_cmd.h            |  33 ++++
 drivers/net/hns3/hns3_ethdev.c         | 120 +++++++++++---
 drivers/net/hns3/hns3_ethdev.h         |  25 +++
 drivers/net/hns3/hns3_ptp.c            | 294 +++++++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_regs.h           |  25 +++
 drivers/net/hns3/hns3_rxtx.c           |  56 ++++++-
 drivers/net/hns3/hns3_rxtx.h           |  12 ++
 drivers/net/hns3/hns3_rxtx_vec.c       |  19 ++-
 drivers/net/hns3/meson.build           |   3 +-
 12 files changed, 554 insertions(+), 37 deletions(-)
 create mode 100644 drivers/net/hns3/hns3_ptp.c
Signature · 1 line
2.7.4
#11 lore raw

PATCH v2 1/2 net/hns3: fix code check warning

This patch fixed cyclomatic complexity about MTU
in device configure process.

Fixes 1f5ca0b460cd ("net/hns3: support some device operations")
---
 drivers/net/hns3/hns3_ethdev.c | 61 +++++++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 24 deletions(-)
drivers/net/hns3/hns3_ethdev.c +37 -24
index 4883cb7..5cc997d 100644
@@ -2373,6 +2373,40 @@ hns3_init_ring_with_vector(struct hns3_hw *hw)
 }
 
 static int
+hns3_refresh_mtu(struct rte_eth_dev *dev, struct rte_eth_conf *conf)
+{
+	struct hns3_adapter *hns = dev->data->dev_private;
+	struct hns3_hw *hw = &hns->hw;
+	uint32_t max_rx_pkt_len;
+	uint16_t mtu;
+	int ret;
+
+	if (!(conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME))
+		return 0;
+
+	/*
+	 * If jumbo frames are enabled, MTU needs to be refreshed
+	 * according to the maximum RX packet length.
+	 */
+	max_rx_pkt_len = conf->rxmode.max_rx_pkt_len;
+	if (max_rx_pkt_len > HNS3_MAX_FRAME_LEN ||
+	    max_rx_pkt_len <= HNS3_DEFAULT_FRAME_LEN) {
+		hns3_err(hw, "maximum Rx packet length must be greater than %u "
+			 "and no more than %u when jumbo frame enabled.",
+			 (uint16_t)HNS3_DEFAULT_FRAME_LEN,
+			 (uint16_t)HNS3_MAX_FRAME_LEN);
+		return -EINVAL;
+	}
+
+	mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(max_rx_pkt_len);
+	ret = hns3_dev_mtu_set(dev, mtu);
+	if (ret)
+		return ret;
+	dev->data->mtu = mtu;
+
+	return 0;
+}
+static int
 hns3_dev_configure(struct rte_eth_dev *dev)
 {
 	struct hns3_adapter *hns = dev->data->dev_private;
@@ -2382,8 +2416,6 @@ hns3_dev_configure(struct rte_eth_dev *dev)
 	uint16_t nb_rx_q = dev->data->nb_rx_queues;
 	uint16_t nb_tx_q = dev->data->nb_tx_queues;
 	struct rte_eth_rss_conf rss_conf;
-	uint32_t max_rx_pkt_len;
-	uint16_t mtu;
 	bool gro_en;
 	int ret;
 
@@ -2431,28 +2463,9 @@ hns3_dev_configure(struct rte_eth_dev *dev)
 			goto cfg_err;
 	}
 
-	/*
-	 * If jumbo frames are enabled, MTU needs to be refreshed
-	 * according to the maximum RX packet length.
-	 */
-	if (conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
-		max_rx_pkt_len = conf->rxmode.max_rx_pkt_len;
-		if (max_rx_pkt_len > HNS3_MAX_FRAME_LEN ||
-		    max_rx_pkt_len <= HNS3_DEFAULT_FRAME_LEN) {
-			hns3_err(hw, "maximum Rx packet length must be greater "
-				 "than %u and less than %u when jumbo frame enabled.",
-				 (uint16_t)HNS3_DEFAULT_FRAME_LEN,
-				 (uint16_t)HNS3_MAX_FRAME_LEN);
-			ret = -EINVAL;
-			goto cfg_err;
-		}
-
-		mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(max_rx_pkt_len);
-		ret = hns3_dev_mtu_set(dev, mtu);
-		if (ret)
-			goto cfg_err;
-		dev->data->mtu = mtu;
-	}
+	ret = hns3_refresh_mtu(dev, conf);
+	if (ret)
+		goto cfg_err;
 
 	ret = hns3_dev_configure_vlan(dev);
 	if (ret)
Signature · 1 line
2.7.4
#12 lore raw

PATCH v2 2/2 net/hns3: support IEEE 1588 PTP

In reply to Min Hu (Connor)

Add hns3 support for new ethdev APIs to enable and read IEEE1588/ 802.1AS PTP timestamps.

---
 doc/guides/nics/features/hns3.ini      |   2 +
 doc/guides/nics/hns3.rst               |   1 +
 doc/guides/rel_notes/release_21_05.rst |   1 +
 drivers/net/hns3/hns3_cmd.h            |  33 ++++
 drivers/net/hns3/hns3_ethdev.c         |  59 ++++++-
 drivers/net/hns3/hns3_ethdev.h         |  25 +++
 drivers/net/hns3/hns3_ptp.c            | 294 +++++++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_regs.h           |  25 +++
 drivers/net/hns3/hns3_rxtx.c           |  56 ++++++-
 drivers/net/hns3/hns3_rxtx.h           |  12 ++
 drivers/net/hns3/hns3_rxtx_vec.c       |  19 ++-
 drivers/net/hns3/meson.build           |   3 +-
 12 files changed, 517 insertions(+), 13 deletions(-)
 create mode 100644 drivers/net/hns3/hns3_ptp.c
doc/guides/nics/features/hns3.ini +2 -0
index 3988be4..502bfe7 100644
@@ -43,6 +43,8 @@ Stats per queue      = Y
 FW version           = Y
 Registers dump       = Y
 Module EEPROM dump   = Y
+Timesync             = Y
+Timestamp offload    = Y
 Multiprocess aware   = Y
 Linux                = Y
 ARMv8                = Y
doc/guides/nics/hns3.rst +1 -0
index ccd2f6f..3366562 100644
@@ -37,6 +37,7 @@ Features of the HNS3 PMD are:
 - MTU update
 - NUMA support
 - Generic flow API
+- IEEE1588/802.1AS timestamping
 
 Prerequisites
 -------------
doc/guides/rel_notes/release_21_05.rst +1 -0
index a899818..202ca92 100644
@@ -90,6 +90,7 @@ New Features
   * Added support for outer UDP checksum in Kunpeng930.
   * Added support for query Tx descriptor status.
   * Added support for query Rx descriptor status.
+  * Added support for IEEE 1588 PTP.
 
 * **Updated NXP DPAA driver.**
 
drivers/net/hns3/hns3_cmd.h +33 -0
index 30aca82..c9631e8 100644
@@ -123,6 +123,12 @@ enum hns3_opcode_type {
 	HNS3_OPC_CLEAR_MAC_TNL_INT      = 0x0312,
 	HNS3_OPC_CONFIG_FEC_MODE        = 0x031A,
 
+#ifdef RTE_LIBRTE_IEEE1588
+	/* PTP command */
+	HNS3_OPC_PTP_INT_EN             = 0x0501,
+	HNS3_OPC_CFG_PTP_MODE           = 0x0507,
+#endif
+
 	/* PFC/Pause commands */
 	HNS3_OPC_CFG_MAC_PAUSE_EN       = 0x0701,
 	HNS3_OPC_CFG_PFC_PAUSE_EN       = 0x0702,
@@ -975,6 +981,33 @@ struct hns3_query_ssu_cmd {
 	uint32_t oq_drop_cnt;
 	uint32_t rev1[2];
 };
+#ifdef RTE_LIBRTE_IEEE1588
+#define HNS3_PTP_ENABLE_B               0
+#define HNS3_PTP_TX_ENABLE_B            1
+#define HNS3_PTP_RX_ENABLE_B            2
+
+#define HNS3_PTP_TYPE_S                 0
+#define HNS3_PTP_TYPE_M                (0x3 << HNS3_PTP_TYPE_S)
+
+#define ALL_PTP_V2_TYPE                 0xF
+#define HNS3_PTP_MESSAGE_TYPE_S         0
+#define HNS3_PTP_MESSAGE_TYPE_M        (0xF << HNS3_PTP_MESSAGE_TYPE_S)
+
+#define PTP_TYPE_L2_V2_TYPE             0
+
+struct hns3_ptp_mode_cfg_cmd {
+	uint8_t enable;
+	uint8_t ptp_type;
+	uint8_t v2_message_type_1;
+	uint8_t v2_message_type_0;
+	uint8_t rsv[20];
+};
+
+struct hns3_ptp_int_cmd {
+	uint8_t int_en;
+	uint8_t rsvd[23];
+};
+#endif
 
 #define HNS3_MAX_TQP_NUM_HIP08_PF	64
 #define HNS3_DEFAULT_TX_BUF		0x4000    /* 16k  bytes */
drivers/net/hns3/hns3_ethdev.c +58 -1

116 lines not on this page · raw message

drivers/net/hns3/hns3_ethdev.h +25 -0
index ac255a3..a360efb 100644
@@ -750,6 +750,13 @@ struct hns3_pf {
 	bool support_sfp_query;
 	uint32_t fec_mode; /* current FEC mode for ethdev */
 
+#ifdef RTE_LIBRTE_IEEE1588
+	bool ptp_enable;
+
+	/* Stores timestamp of last received packet on dev */
+	uint64_t rx_timestamp;
+#endif
+
 	struct hns3_vtag_cfg vtag_config;
 	LIST_HEAD(vlan_tbl, hns3_user_vlan_table) vlan_list;
 
@@ -1000,6 +1007,24 @@ void hns3vf_update_link_status(struct hns3_hw *hw, uint8_t link_status,
 			  uint32_t link_speed, uint8_t link_duplex);
 void hns3_parse_devargs(struct rte_eth_dev *dev);
 
+#ifdef RTE_LIBRTE_IEEE1588
+int hns3_restore_ptp(struct hns3_adapter *hns);
+int hns3_mbuf_dyn_rx_timestamp_register(struct rte_eth_dev *dev,
+				    struct rte_eth_conf *conf);
+int hns3_ptp_init(struct hns3_hw *hw);
+int hns3_timesync_enable(struct rte_eth_dev *dev);
+int hns3_timesync_disable(struct rte_eth_dev *dev);
+int hns3_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
+				struct timespec *timestamp,
+				uint32_t flags __rte_unused);
+int hns3_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
+				struct timespec *timestamp);
+int hns3_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts);
+int hns3_timesync_write_time(struct rte_eth_dev *dev,
+			const struct timespec *ts);
+int hns3_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
+#endif
+
 static inline bool
 is_reset_pending(struct hns3_adapter *hns)
 {
drivers/net/hns3/hns3_ptp.c new file +294 -0

294 lines not on this page · raw message

drivers/net/hns3/hns3_regs.h +25 -0
index e141fe1..58a20ca 100644
@@ -121,6 +121,31 @@
 #define HNS3_TQP_INTR_RL_DEFAULT		0
 #define HNS3_TQP_INTR_QL_DEFAULT		0
 
+#ifdef RTE_LIBRTE_IEEE1588
+/* Register bit for 1588 event */
+#define HNS3_VECTOR0_1588_INT_B	                0
+
+#define HNS3_PTP_BASE_ADDRESS			0x29000
+
+#define HNS3_TX_1588_SEQID_BACK			(HNS3_PTP_BASE_ADDRESS + 0x0)
+#define HNS3_TX_1588_TSP_BACK_0			(HNS3_PTP_BASE_ADDRESS + 0x4)
+#define HNS3_TX_1588_TSP_BACK_1			(HNS3_PTP_BASE_ADDRESS + 0x8)
+#define HNS3_TX_1588_TSP_BACK_2			(HNS3_PTP_BASE_ADDRESS + 0xc)
+
+#define HNS3_TX_1588_BACK_TSP_CNT		(HNS3_PTP_BASE_ADDRESS + 0x30)
+
+#define HNS3_CFG_TIME_SYNC_H			(HNS3_PTP_BASE_ADDRESS + 0x50)
+#define HNS3_CFG_TIME_SYNC_M			(HNS3_PTP_BASE_ADDRESS + 0x54)
+#define HNS3_CFG_TIME_SYNC_L			(HNS3_PTP_BASE_ADDRESS + 0x58)
+#define HNS3_CFG_TIME_SYNC_RDY			(HNS3_PTP_BASE_ADDRESS + 0x5c)
+
+#define HNS3_CFG_TIME_CYC_EN			(HNS3_PTP_BASE_ADDRESS + 0x70)
+
+#define HNS3_CURR_TIME_OUT_H			(HNS3_PTP_BASE_ADDRESS + 0x74)
+#define HNS3_CURR_TIME_OUT_L			(HNS3_PTP_BASE_ADDRESS + 0x78)
+#define HNS3_CURR_TIME_OUT_NS			(HNS3_PTP_BASE_ADDRESS + 0x7c)
+#endif
+
 /* gl_usec convert to hardware count, as writing each 1 represents 2us */
 #define HNS3_GL_USEC_TO_REG(gl_usec)		((gl_usec) >> 1)
 /* rl_usec convert to hardware count, as writing each 1 represents 4us */
drivers/net/hns3/hns3_rxtx.c +52 -4

109 lines not on this page · raw message

drivers/net/hns3/hns3_rxtx.h +12 -0
index 6689397..ded5b0b 100644
@@ -106,6 +106,8 @@
 #define HNS3_RXD_L3L4P_B			11
 #define HNS3_RXD_TSIND_S			12
 #define HNS3_RXD_TSIND_M			(0x7 << HNS3_RXD_TSIND_S)
+
+#define HNS3_RXD_TS_VLD_B			14
 #define HNS3_RXD_LKBK_B				15
 #define HNS3_RXD_GRO_SIZE_S			16
 #define HNS3_RXD_GRO_SIZE_M			(0x3fff << HNS3_RXD_GRO_SIZE_S)
@@ -200,6 +202,11 @@ enum hns3_pkt_tun_type {
 struct hns3_desc {
 	union {
 		uint64_t addr;
+
+#ifdef RTE_LIBRTE_IEEE1588
+		uint64_t timestamp;
+#endif
+
 		struct {
 			uint32_t addr0;
 			uint32_t addr1;
@@ -534,6 +541,11 @@ enum hns3_cksum_status {
 	HNS3_OUTER_L4_CKSUM_ERR = 8
 };
 
+#ifdef RTE_LIBRTE_IEEE1588
+extern uint64_t hns3_timestamp_rx_dynflag;
+extern int hns3_timestamp_dynfield_offset;
+#endif
+
 static inline int
 hns3_handle_bdinfo(struct hns3_rx_queue *rxq, struct rte_mbuf *rxm,
 		   uint32_t bd_base_info, uint32_t l234_info,
drivers/net/hns3/hns3_rxtx_vec.c +12 -7
index 2bc4372..4584d8a 100644
@@ -18,6 +18,12 @@ hns3_tx_check_vec_support(struct rte_eth_dev *dev)
 {
 	struct rte_eth_txmode *txmode = &dev->data->dev_conf.txmode;
 
+#ifdef RTE_LIBRTE_IEEE1588
+	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	if (hns3_dev_ptp_supported(hw))
+		return -ENOTSUP;
+#endif
+
 	/* Only support DEV_TX_OFFLOAD_MBUF_FAST_FREE */
 	if (txmode->offloads != DEV_TX_OFFLOAD_MBUF_FAST_FREE)
 		return -ENOTSUP;
@@ -167,7 +173,6 @@ hns3_rxq_vec_setup(struct hns3_rx_queue *rxq)
 	memset(rxq->offset_table, 0, sizeof(rxq->offset_table));
 }
 
-#ifndef RTE_LIBRTE_IEEE1588
 static int
 hns3_rxq_vec_check(struct hns3_rx_queue *rxq, void *arg)
 {
@@ -183,17 +188,21 @@ hns3_rxq_vec_check(struct hns3_rx_queue *rxq, void *arg)
 	RTE_SET_USED(arg);
 	return 0;
 }
-#endif
 
 int
 hns3_rx_check_vec_support(struct rte_eth_dev *dev)
 {
-#ifndef RTE_LIBRTE_IEEE1588
 	struct rte_fdir_conf *fconf = &dev->data->dev_conf.fdir_conf;
 	struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
 	uint64_t offloads_mask = DEV_RX_OFFLOAD_TCP_LRO |
 				 DEV_RX_OFFLOAD_VLAN;
 
+#ifdef RTE_LIBRTE_IEEE1588
+	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	if (hns3_dev_ptp_supported(hw))
+		return -ENOTSUP;
+#endif
+
 	if (dev->data->scattered_rx)
 		return -ENOTSUP;
 
@@ -207,8 +216,4 @@ hns3_rx_check_vec_support(struct rte_eth_dev *dev)
 		return -ENOTSUP;
 
 	return 0;
-#else
-	RTE_SET_USED(dev);
-	return -ENOTSUP;
-#endif
 }
drivers/net/hns3/meson.build +2 -1
index f6aac69..6d78c33 100644
@@ -26,7 +26,8 @@ sources = files('hns3_cmd.c',
 	'hns3_rxtx.c',
 	'hns3_stats.c',
 	'hns3_mp.c',
-	'hns3_tm.c')
+	'hns3_tm.c',
+	'hns3_ptp.c')
 
 deps += ['hash']
 
Signature · 1 line
2.7.4
#13 lore raw

v3 cover Support PTP for hns3 PMD

In reply to Min Hu (Connor)

This set includes two patches, one patch is to fix cyclomatic complexity, the other patch is to support PTP, but depends on the first patch. So the two forms one set of patches.
---
v3:
* Delete "RTE_LIBRTE_IEEE1588".

v2:
* Add release doc for version 21.05.

Min Hu (Connor) (2):
net/hns3: fix code check warning
net/hns3: support IEEE 1588 PTP

 doc/guides/nics/features/hns3.ini      |   2 +
 doc/guides/nics/hns3.rst               |   1 +
 doc/guides/rel_notes/release_21_05.rst |   1 +
 drivers/net/hns3/hns3_cmd.h            |  30 ++++
 drivers/net/hns3/hns3_ethdev.c         | 100 ++++++++---
 drivers/net/hns3/hns3_ethdev.h         |  20 +++
 drivers/net/hns3/hns3_ptp.c            | 292 +++++++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_regs.h           |  23 +++
 drivers/net/hns3/hns3_rxtx.c           |  47 +++++-
 drivers/net/hns3/hns3_rxtx.h           |   7 +
 drivers/net/hns3/hns3_rxtx_vec.c       |  15 +-
 drivers/net/hns3/meson.build           |   3 +-
 12 files changed, 505 insertions(+), 36 deletions(-)
 create mode 100644 drivers/net/hns3/hns3_ptp.c
Signature · 1 line
2.7.4
#14 lore raw

PATCH v3 1/2 net/hns3: fix code check warning

This patch fixed cyclomatic complexity about MTU
in device configure process.

Fixes 1f5ca0b460cd ("net/hns3: support some device operations")
---
 drivers/net/hns3/hns3_ethdev.c | 61 +++++++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 24 deletions(-)
drivers/net/hns3/hns3_ethdev.c +37 -24
index 9c71808..bb71808 100644
@@ -2373,6 +2373,40 @@ hns3_init_ring_with_vector(struct hns3_hw *hw)
 }
 
 static int
+hns3_refresh_mtu(struct rte_eth_dev *dev, struct rte_eth_conf *conf)
+{
+	struct hns3_adapter *hns = dev->data->dev_private;
+	struct hns3_hw *hw = &hns->hw;
+	uint32_t max_rx_pkt_len;
+	uint16_t mtu;
+	int ret;
+
+	if (!(conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME))
+		return 0;
+
+	/*
+	 * If jumbo frames are enabled, MTU needs to be refreshed
+	 * according to the maximum RX packet length.
+	 */
+	max_rx_pkt_len = conf->rxmode.max_rx_pkt_len;
+	if (max_rx_pkt_len > HNS3_MAX_FRAME_LEN ||
+	    max_rx_pkt_len <= HNS3_DEFAULT_FRAME_LEN) {
+		hns3_err(hw, "maximum Rx packet length must be greater than %u "
+			 "and no more than %u when jumbo frame enabled.",
+			 (uint16_t)HNS3_DEFAULT_FRAME_LEN,
+			 (uint16_t)HNS3_MAX_FRAME_LEN);
+		return -EINVAL;
+	}
+
+	mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(max_rx_pkt_len);
+	ret = hns3_dev_mtu_set(dev, mtu);
+	if (ret)
+		return ret;
+	dev->data->mtu = mtu;
+
+	return 0;
+}
+static int
 hns3_dev_configure(struct rte_eth_dev *dev)
 {
 	struct hns3_adapter *hns = dev->data->dev_private;
@@ -2382,8 +2416,6 @@ hns3_dev_configure(struct rte_eth_dev *dev)
 	uint16_t nb_rx_q = dev->data->nb_rx_queues;
 	uint16_t nb_tx_q = dev->data->nb_tx_queues;
 	struct rte_eth_rss_conf rss_conf;
-	uint32_t max_rx_pkt_len;
-	uint16_t mtu;
 	bool gro_en;
 	int ret;
 
@@ -2431,28 +2463,9 @@ hns3_dev_configure(struct rte_eth_dev *dev)
 			goto cfg_err;
 	}
 
-	/*
-	 * If jumbo frames are enabled, MTU needs to be refreshed
-	 * according to the maximum RX packet length.
-	 */
-	if (conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
-		max_rx_pkt_len = conf->rxmode.max_rx_pkt_len;
-		if (max_rx_pkt_len > HNS3_MAX_FRAME_LEN ||
-		    max_rx_pkt_len <= HNS3_DEFAULT_FRAME_LEN) {
-			hns3_err(hw, "maximum Rx packet length must be greater "
-				 "than %u and less than %u when jumbo frame enabled.",
-				 (uint16_t)HNS3_DEFAULT_FRAME_LEN,
-				 (uint16_t)HNS3_MAX_FRAME_LEN);
-			ret = -EINVAL;
-			goto cfg_err;
-		}
-
-		mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(max_rx_pkt_len);
-		ret = hns3_dev_mtu_set(dev, mtu);
-		if (ret)
-			goto cfg_err;
-		dev->data->mtu = mtu;
-	}
+	ret = hns3_refresh_mtu(dev, conf);
+	if (ret)
+		goto cfg_err;
 
 	ret = hns3_dev_configure_vlan(dev);
 	if (ret)
Signature · 1 line
2.7.4
#15 lore raw

PATCH v3 2/2 net/hns3: support IEEE 1588 PTP

In reply to Min Hu (Connor)

Add hns3 support for new ethdev APIs to enable and read IEEE1588/ 802.1AS PTP timestamps.

---
 doc/guides/nics/features/hns3.ini      |   2 +
 doc/guides/nics/hns3.rst               |   1 +
 doc/guides/rel_notes/release_21_05.rst |   1 +
 drivers/net/hns3/hns3_cmd.h            |  30 ++++
 drivers/net/hns3/hns3_ethdev.c         |  41 ++++-
 drivers/net/hns3/hns3_ethdev.h         |  20 +++
 drivers/net/hns3/hns3_ptp.c            | 292 +++++++++++++++++++++++++++++++++
 drivers/net/hns3/hns3_regs.h           |  23 +++
 drivers/net/hns3/hns3_rxtx.c           |  47 +++++-
 drivers/net/hns3/hns3_rxtx.h           |   7 +
 drivers/net/hns3/hns3_rxtx_vec.c       |  15 +-
 drivers/net/hns3/meson.build           |   3 +-
 12 files changed, 469 insertions(+), 13 deletions(-)
 create mode 100644 drivers/net/hns3/hns3_ptp.c
doc/guides/nics/features/hns3.ini +2 -0
index 3988be4..502bfe7 100644
@@ -43,6 +43,8 @@ Stats per queue      = Y
 FW version           = Y
 Registers dump       = Y
 Module EEPROM dump   = Y
+Timesync             = Y
+Timestamp offload    = Y
 Multiprocess aware   = Y
 Linux                = Y
 ARMv8                = Y
doc/guides/nics/hns3.rst +1 -0
index ccd2f6f..3366562 100644
@@ -37,6 +37,7 @@ Features of the HNS3 PMD are:
 - MTU update
 - NUMA support
 - Generic flow API
+- IEEE1588/802.1AS timestamping
 
 Prerequisites
 -------------
doc/guides/rel_notes/release_21_05.rst +1 -0
index 873140b..2ffeb92 100644
@@ -90,6 +90,7 @@ New Features
   * Added support for outer UDP checksum in Kunpeng930.
   * Added support for query Tx descriptor status.
   * Added support for query Rx descriptor status.
+  * Added support for IEEE 1588 PTP.
 
 * **Updated Intel iavf driver.**
 
drivers/net/hns3/hns3_cmd.h +30 -0
index 30aca82..5d1fb67 100644
@@ -123,6 +123,10 @@ enum hns3_opcode_type {
 	HNS3_OPC_CLEAR_MAC_TNL_INT      = 0x0312,
 	HNS3_OPC_CONFIG_FEC_MODE        = 0x031A,
 
+	/* PTP command */
+	HNS3_OPC_PTP_INT_EN             = 0x0501,
+	HNS3_OPC_CFG_PTP_MODE           = 0x0507,
+
 	/* PFC/Pause commands */
 	HNS3_OPC_CFG_MAC_PAUSE_EN       = 0x0701,
 	HNS3_OPC_CFG_PFC_PAUSE_EN       = 0x0702,
@@ -976,6 +980,32 @@ struct hns3_query_ssu_cmd {
 	uint32_t rev1[2];
 };
 
+#define HNS3_PTP_ENABLE_B               0
+#define HNS3_PTP_TX_ENABLE_B            1
+#define HNS3_PTP_RX_ENABLE_B            2
+
+#define HNS3_PTP_TYPE_S                 0
+#define HNS3_PTP_TYPE_M                (0x3 << HNS3_PTP_TYPE_S)
+
+#define ALL_PTP_V2_TYPE                 0xF
+#define HNS3_PTP_MESSAGE_TYPE_S         0
+#define HNS3_PTP_MESSAGE_TYPE_M        (0xF << HNS3_PTP_MESSAGE_TYPE_S)
+
+#define PTP_TYPE_L2_V2_TYPE             0
+
+struct hns3_ptp_mode_cfg_cmd {
+	uint8_t enable;
+	uint8_t ptp_type;
+	uint8_t v2_message_type_1;
+	uint8_t v2_message_type_0;
+	uint8_t rsv[20];
+};
+
+struct hns3_ptp_int_cmd {
+	uint8_t int_en;
+	uint8_t rsvd[23];
+};
+
 #define HNS3_MAX_TQP_NUM_HIP08_PF	64
 #define HNS3_DEFAULT_TX_BUF		0x4000    /* 16k  bytes */
 #define HNS3_TOTAL_PKT_BUF		0x108000  /* 1.03125M bytes */
drivers/net/hns3/hns3_ethdev.c +40 -1

98 lines not on this page · raw message

drivers/net/hns3/hns3_ethdev.h +20 -0
index ac255a3..d23239d 100644
@@ -750,6 +750,11 @@ struct hns3_pf {
 	bool support_sfp_query;
 	uint32_t fec_mode; /* current FEC mode for ethdev */
 
+	bool ptp_enable;
+
+	/* Stores timestamp of last received packet on dev */
+	uint64_t rx_timestamp;
+
 	struct hns3_vtag_cfg vtag_config;
 	LIST_HEAD(vlan_tbl, hns3_user_vlan_table) vlan_list;
 
@@ -999,6 +1004,21 @@ int hns3_dev_infos_get(struct rte_eth_dev *eth_dev,
 void hns3vf_update_link_status(struct hns3_hw *hw, uint8_t link_status,
 			  uint32_t link_speed, uint8_t link_duplex);
 void hns3_parse_devargs(struct rte_eth_dev *dev);
+int hns3_restore_ptp(struct hns3_adapter *hns);
+int hns3_mbuf_dyn_rx_timestamp_register(struct rte_eth_dev *dev,
+				    struct rte_eth_conf *conf);
+int hns3_ptp_init(struct hns3_hw *hw);
+int hns3_timesync_enable(struct rte_eth_dev *dev);
+int hns3_timesync_disable(struct rte_eth_dev *dev);
+int hns3_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
+				struct timespec *timestamp,
+				uint32_t flags __rte_unused);
+int hns3_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
+				struct timespec *timestamp);
+int hns3_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts);
+int hns3_timesync_write_time(struct rte_eth_dev *dev,
+			const struct timespec *ts);
+int hns3_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
 
 static inline bool
 is_reset_pending(struct hns3_adapter *hns)
drivers/net/hns3/hns3_ptp.c new file +292 -0

292 lines not on this page · raw message

drivers/net/hns3/hns3_regs.h +23 -0
index e141fe1..c9e10be 100644
@@ -121,6 +121,29 @@
 #define HNS3_TQP_INTR_RL_DEFAULT		0
 #define HNS3_TQP_INTR_QL_DEFAULT		0
 
+/* Register bit for 1588 event */
+#define HNS3_VECTOR0_1588_INT_B	                0
+
+#define HNS3_PTP_BASE_ADDRESS			0x29000
+
+#define HNS3_TX_1588_SEQID_BACK			(HNS3_PTP_BASE_ADDRESS + 0x0)
+#define HNS3_TX_1588_TSP_BACK_0			(HNS3_PTP_BASE_ADDRESS + 0x4)
+#define HNS3_TX_1588_TSP_BACK_1			(HNS3_PTP_BASE_ADDRESS + 0x8)
+#define HNS3_TX_1588_TSP_BACK_2			(HNS3_PTP_BASE_ADDRESS + 0xc)
+
+#define HNS3_TX_1588_BACK_TSP_CNT		(HNS3_PTP_BASE_ADDRESS + 0x30)
+
+#define HNS3_CFG_TIME_SYNC_H			(HNS3_PTP_BASE_ADDRESS + 0x50)
+#define HNS3_CFG_TIME_SYNC_M			(HNS3_PTP_BASE_ADDRESS + 0x54)
+#define HNS3_CFG_TIME_SYNC_L			(HNS3_PTP_BASE_ADDRESS + 0x58)
+#define HNS3_CFG_TIME_SYNC_RDY			(HNS3_PTP_BASE_ADDRESS + 0x5c)
+
+#define HNS3_CFG_TIME_CYC_EN			(HNS3_PTP_BASE_ADDRESS + 0x70)
+
+#define HNS3_CURR_TIME_OUT_H			(HNS3_PTP_BASE_ADDRESS + 0x74)
+#define HNS3_CURR_TIME_OUT_L			(HNS3_PTP_BASE_ADDRESS + 0x78)
+#define HNS3_CURR_TIME_OUT_NS			(HNS3_PTP_BASE_ADDRESS + 0x7c)
+
 /* gl_usec convert to hardware count, as writing each 1 represents 2us */
 #define HNS3_GL_USEC_TO_REG(gl_usec)		((gl_usec) >> 1)
 /* rl_usec convert to hardware count, as writing each 1 represents 4us */
drivers/net/hns3/hns3_rxtx.c +43 -4

100 lines not on this page · raw message

drivers/net/hns3/hns3_rxtx.h +7 -0
index 6689397..eebbebf 100644
@@ -106,6 +106,8 @@
 #define HNS3_RXD_L3L4P_B			11
 #define HNS3_RXD_TSIND_S			12
 #define HNS3_RXD_TSIND_M			(0x7 << HNS3_RXD_TSIND_S)
+
+#define HNS3_RXD_TS_VLD_B			14
 #define HNS3_RXD_LKBK_B				15
 #define HNS3_RXD_GRO_SIZE_S			16
 #define HNS3_RXD_GRO_SIZE_M			(0x3fff << HNS3_RXD_GRO_SIZE_S)
@@ -200,6 +202,8 @@ enum hns3_pkt_tun_type {
 struct hns3_desc {
 	union {
 		uint64_t addr;
+		uint64_t timestamp;
+
 		struct {
 			uint32_t addr0;
 			uint32_t addr1;
@@ -534,6 +538,9 @@ enum hns3_cksum_status {
 	HNS3_OUTER_L4_CKSUM_ERR = 8
 };
 
+extern uint64_t hns3_timestamp_rx_dynflag;
+extern int hns3_timestamp_dynfield_offset;
+
 static inline int
 hns3_handle_bdinfo(struct hns3_rx_queue *rxq, struct rte_mbuf *rxm,
 		   uint32_t bd_base_info, uint32_t l234_info,
drivers/net/hns3/hns3_rxtx_vec.c +8 -7
index 2bc4372..030bfdb 100644
@@ -18,6 +18,10 @@ hns3_tx_check_vec_support(struct rte_eth_dev *dev)
 {
 	struct rte_eth_txmode *txmode = &dev->data->dev_conf.txmode;
 
+	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	if (hns3_dev_ptp_supported(hw))
+		return -ENOTSUP;
+
 	/* Only support DEV_TX_OFFLOAD_MBUF_FAST_FREE */
 	if (txmode->offloads != DEV_TX_OFFLOAD_MBUF_FAST_FREE)
 		return -ENOTSUP;
@@ -167,7 +171,6 @@ hns3_rxq_vec_setup(struct hns3_rx_queue *rxq)
 	memset(rxq->offset_table, 0, sizeof(rxq->offset_table));
 }
 
-#ifndef RTE_LIBRTE_IEEE1588
 static int
 hns3_rxq_vec_check(struct hns3_rx_queue *rxq, void *arg)
 {
@@ -183,17 +186,19 @@ hns3_rxq_vec_check(struct hns3_rx_queue *rxq, void *arg)
 	RTE_SET_USED(arg);
 	return 0;
 }
-#endif
 
 int
 hns3_rx_check_vec_support(struct rte_eth_dev *dev)
 {
-#ifndef RTE_LIBRTE_IEEE1588
 	struct rte_fdir_conf *fconf = &dev->data->dev_conf.fdir_conf;
 	struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
 	uint64_t offloads_mask = DEV_RX_OFFLOAD_TCP_LRO |
 				 DEV_RX_OFFLOAD_VLAN;
 
+	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+	if (hns3_dev_ptp_supported(hw))
+		return -ENOTSUP;
+
 	if (dev->data->scattered_rx)
 		return -ENOTSUP;
 
@@ -207,8 +212,4 @@ hns3_rx_check_vec_support(struct rte_eth_dev *dev)
 		return -ENOTSUP;
 
 	return 0;
-#else
-	RTE_SET_USED(dev);
-	return -ENOTSUP;
-#endif
 }
drivers/net/hns3/meson.build +2 -1
index f6aac69..6d78c33 100644
@@ -26,7 +26,8 @@ sources = files('hns3_cmd.c',
 	'hns3_rxtx.c',
 	'hns3_stats.c',
 	'hns3_mp.c',
-	'hns3_tm.c')
+	'hns3_tm.c',
+	'hns3_ptp.c')
 
 deps += ['hash']
 
Signature · 1 line
2.7.4
#16 lore raw
In reply to Min Hu (Connor)
Quoted 8 lines · Min Hu (Connor)

This set includes two patches, one patch is to fix cyclomatic complexity, the other patch is to support PTP, but depends on the first patch. So the two forms one set of patches.
---
v3:
* Delete "RTE_LIBRTE_IEEE1588".

Quoted 7 lines

v2:
* Add release doc for version 21.05.

Min Hu (Connor) (2):
net/hns3: fix code check warning
net/hns3: support IEEE 1588 PTP

Series applied to dpdk-next-net/main, thanks.