Skip to contentSkip to conversation

net/igc: support PTP timesync

PATCH Superseded Simei Su 2 participants 11 messages Dec 20, 2022 – Jan 29, 2023 Network drivers

lore
Share & tools
lore

Simei Su

author
#0 lore raw

cover net/igc: support PTP timesync

[PATCH 1/3] code refactoring.
[PATCH 2/3] add related definitions for ptp timesync. [PATCH 3/3] add IEEE1588 API to support timesync.

Simei Su (3):
net/igc: code refactoring
net/igc/base: support PTP timesync
net/igc: support IEEE 1588 PTP

 drivers/net/igc/base/igc_defines.h |  11 ++
 drivers/net/igc/igc_ethdev.c       | 222 +++++++++++++++++++++++++++++++++++++
 drivers/net/igc/igc_ethdev.h       |   4 +-
 drivers/net/igc/igc_txrx.c         | 166 ++++++++-------------------
 drivers/net/igc/igc_txrx.h         | 116 +++++++++++++++++++
 5 files changed, 397 insertions(+), 122 deletions(-)
Signature · 1 line
2.9.5
author
#1 lore raw

PATCH 1/3 net/igc: code refactoring

Move related structures for Rx/Tx queue from igc_txrx.c to igc_txrx.h to make code cleaner and variables used more conveniently.

---
 drivers/net/igc/igc_txrx.c | 118 ---------------------------------------------
 drivers/net/igc/igc_txrx.h | 115 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 118 deletions(-)
drivers/net/igc/igc_txrx.c +0 -118
index ffd219b..c462e91 100644
@@ -93,124 +93,6 @@
 
 #define IGC_TX_OFFLOAD_NOTSUP_MASK (RTE_MBUF_F_TX_OFFLOAD_MASK ^ IGC_TX_OFFLOAD_MASK)
 
-/**
- * Structure associated with each descriptor of the RX ring of a RX queue.
- */
-struct igc_rx_entry {
-	struct rte_mbuf *mbuf; /**< mbuf associated with RX descriptor. */
-};
-
-/**
- * Structure associated with each RX queue.
- */
-struct igc_rx_queue {
-	struct rte_mempool  *mb_pool;   /**< mbuf pool to populate RX ring. */
-	volatile union igc_adv_rx_desc *rx_ring;
-	/**< RX ring virtual address. */
-	uint64_t            rx_ring_phys_addr; /**< RX ring DMA address. */
-	volatile uint32_t   *rdt_reg_addr; /**< RDT register address. */
-	volatile uint32_t   *rdh_reg_addr; /**< RDH register address. */
-	struct igc_rx_entry *sw_ring;   /**< address of RX software ring. */
-	struct rte_mbuf *pkt_first_seg; /**< First segment of current packet. */
-	struct rte_mbuf *pkt_last_seg;  /**< Last segment of current packet. */
-	uint16_t            nb_rx_desc; /**< number of RX descriptors. */
-	uint16_t            rx_tail;    /**< current value of RDT register. */
-	uint16_t            nb_rx_hold; /**< number of held free RX desc. */
-	uint16_t            rx_free_thresh; /**< max free RX desc to hold. */
-	uint16_t            queue_id;   /**< RX queue index. */
-	uint16_t            reg_idx;    /**< RX queue register index. */
-	uint16_t            port_id;    /**< Device port identifier. */
-	uint8_t             pthresh;    /**< Prefetch threshold register. */
-	uint8_t             hthresh;    /**< Host threshold register. */
-	uint8_t             wthresh;    /**< Write-back threshold register. */
-	uint8_t             crc_len;    /**< 0 if CRC stripped, 4 otherwise. */
-	uint8_t             drop_en;	/**< If not 0, set SRRCTL.Drop_En. */
-	uint32_t            flags;      /**< RX flags. */
-	uint64_t	    offloads;   /**< offloads of RTE_ETH_RX_OFFLOAD_* */
-};
-
-/** Offload features */
-union igc_tx_offload {
-	uint64_t data;
-	struct {
-		uint64_t l3_len:9; /**< L3 (IP) Header Length. */
-		uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
-		uint64_t vlan_tci:16;
-		/**< VLAN Tag Control Identifier(CPU order). */
-		uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */
-		uint64_t tso_segsz:16; /**< TCP TSO segment size. */
-		/* uint64_t unused:8; */
-	};
-};
-
-/*
- * Compare mask for igc_tx_offload.data,
- * should be in sync with igc_tx_offload layout.
- */
-#define TX_MACIP_LEN_CMP_MASK	0x000000000000FFFFULL /**< L2L3 header mask. */
-#define TX_VLAN_CMP_MASK	0x00000000FFFF0000ULL /**< Vlan mask. */
-#define TX_TCP_LEN_CMP_MASK	0x000000FF00000000ULL /**< TCP header mask. */
-#define TX_TSO_MSS_CMP_MASK	0x00FFFF0000000000ULL /**< TSO segsz mask. */
-/** Mac + IP + TCP + Mss mask. */
-#define TX_TSO_CMP_MASK	\
-	(TX_MACIP_LEN_CMP_MASK | TX_TCP_LEN_CMP_MASK | TX_TSO_MSS_CMP_MASK)
-
-/**
- * Structure to check if new context need be built
- */
-struct igc_advctx_info {
-	uint64_t flags;           /**< ol_flags related to context build. */
-	/** tx offload: vlan, tso, l2-l3-l4 lengths. */
-	union igc_tx_offload tx_offload;
-	/** compare mask for tx offload. */
-	union igc_tx_offload tx_offload_mask;
-};
-
-/**
- * Hardware context number
- */
-enum {
-	IGC_CTX_0    = 0, /**< CTX0    */
-	IGC_CTX_1    = 1, /**< CTX1    */
-	IGC_CTX_NUM  = 2, /**< CTX_NUM */
-};
-
-/**
- * Structure associated with each descriptor of the TX ring of a TX queue.
- */
-struct igc_tx_entry {
-	struct rte_mbuf *mbuf; /**< mbuf associated with TX desc, if any. */
-	uint16_t next_id; /**< Index of next descriptor in ring. */
-	uint16_t last_id; /**< Index of last scattered descriptor. */
-};
-
-/**
- * Structure associated with each TX queue.
- */
-struct igc_tx_queue {
-	volatile union igc_adv_tx_desc *tx_ring; /**< TX ring address */
-	uint64_t               tx_ring_phys_addr; /**< TX ring DMA address. */
-	struct igc_tx_entry    *sw_ring; /**< virtual address of SW ring. */
-	volatile uint32_t      *tdt_reg_addr; /**< Address of TDT register. */
-	uint32_t               txd_type;      /**< Device-specific TXD type */
-	uint16_t               nb_tx_desc;    /**< number of TX descriptors. */
-	uint16_t               tx_tail;  /**< Current value of TDT register. */
-	uint16_t               tx_head;
-	/**< Index of first used TX descriptor. */
-	uint16_t               queue_id; /**< TX queue index. */
-	uint16_t               reg_idx;  /**< TX queue register index. */
-	uint16_t               port_id;  /**< Device port identifier. */
-	uint8_t                pthresh;  /**< Prefetch threshold register. */
-	uint8_t                hthresh;  /**< Host threshold register. */
-	uint8_t                wthresh;  /**< Write-back threshold register. */
-	uint8_t                ctx_curr;
-
-	/**< Start context position for transmit queue. */
-	struct igc_advctx_info ctx_cache[IGC_CTX_NUM];
-	/**< Hardware context history.*/
-	uint64_t	       offloads; /**< offloads of RTE_ETH_TX_OFFLOAD_* */
-};
-
 static inline uint64_t
 rx_desc_statuserr_to_pkt_flags(uint32_t statuserr)
 {
drivers/net/igc/igc_txrx.h +115 -0

121 lines not on this page · raw message

Signature · 1 line
2.9.5
#2 lore raw

RE: [PATCH 1/3] net/igc: code refactoring

Quoted 11 lines

-----Original Message-----
From: Su, Simei <[email protected]>
Sent: Tuesday, December 20, 2022 11:41 AM
To: Zhang, Qi Z <[email protected]>; Guo, Junfeng <[email protected]>
Cc: [email protected]; Wu, Wenjun1 <[email protected]>; Su, Simei <[email protected]>
Subject: [PATCH 1/3] net/igc: code refactoring

Quoted 2 lines

Move related structures for Rx/Tx queue from igc_txrx.c to igc_txrx.h to make code cleaner and variables used more conveniently.

Not sure if this is necessary.
If a structure only be used internally, keep it internally should be OK. Otherwise need to give a reason why to expose it.

Quoted 283 lines
---
 drivers/net/igc/igc_txrx.c | 118 ---------------------------------------------
 drivers/net/igc/igc_txrx.h | 115
+++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 118 deletions(-)
drivers/net/igc/igc_txrx.c index renamed from drivers/net/igc/igc_txrx.c +0 -0

ffd219b..c462e91 100644

drivers/net/igc/igc_txrx.c +0 -20
@@ -93,124 +93,6 @@
 
 #define IGC_TX_OFFLOAD_NOTSUP_MASK
 (RTE_MBUF_F_TX_OFFLOAD_MASK ^ IGC_TX_OFFLOAD_MASK)
 
-/**
- * Structure associated with each descriptor of the RX ring of a RX queue.
- */
-struct igc_rx_entry {
-	struct rte_mbuf *mbuf; /**< mbuf associated with RX descriptor. */
-};
-
-/**
- * Structure associated with each RX queue.
- */
-struct igc_rx_queue {
-	struct rte_mempool  *mb_pool;   /**< mbuf pool to populate RX ring.
 */
-	volatile union igc_adv_rx_desc *rx_ring;
-	/**< RX ring virtual address. */
-	uint64_t            rx_ring_phys_addr; /**< RX ring DMA address. */
-	volatile uint32_t   *rdt_reg_addr; /**< RDT register address. */
-	volatile uint32_t   *rdh_reg_addr; /**< RDH register address. */
-	struct igc_rx_entry *sw_ring;   /**< address of RX software ring. */
-	struct rte_mbuf *pkt_first_seg; /**< First segment of current packet.
 */
-	struct rte_mbuf *pkt_last_seg;  /**< Last segment of current packet.

*/

drivers/net/igc/igc_txrx.c +0 -14
-	uint16_t            nb_rx_desc; /**< number of RX descriptors. */
-	uint16_t            rx_tail;    /**< current value of RDT register. */
-	uint16_t            nb_rx_hold; /**< number of held free RX desc. */
-	uint16_t            rx_free_thresh; /**< max free RX desc to hold. */
-	uint16_t            queue_id;   /**< RX queue index. */
-	uint16_t            reg_idx;    /**< RX queue register index. */
-	uint16_t            port_id;    /**< Device port identifier. */
-	uint8_t             pthresh;    /**< Prefetch threshold register. */
-	uint8_t             hthresh;    /**< Host threshold register. */
-	uint8_t             wthresh;    /**< Write-back threshold register. */
-	uint8_t             crc_len;    /**< 0 if CRC stripped, 4 otherwise. */
-	uint8_t             drop_en;	/**< If not 0, set SRRCTL.Drop_En. */
-	uint32_t            flags;      /**< RX flags. */
-	uint64_t	    offloads;   /**< offloads of

RTE_ETH_RX_OFFLOAD_* */

drivers/net/igc/igc_txrx.c +0 -21
-};
-
-/** Offload features */
-union igc_tx_offload {
-	uint64_t data;
-	struct {
-		uint64_t l3_len:9; /**< L3 (IP) Header Length. */
-		uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
-		uint64_t vlan_tci:16;
-		/**< VLAN Tag Control Identifier(CPU order). */
-		uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */
-		uint64_t tso_segsz:16; /**< TCP TSO segment size. */
-		/* uint64_t unused:8; */
-	};
-};
-
-/*
- * Compare mask for igc_tx_offload.data,
- * should be in sync with igc_tx_offload layout.
- */
-#define TX_MACIP_LEN_CMP_MASK	0x000000000000FFFFULL /**< L2L3

header mask. */
-#define TX_VLAN_CMP_MASK 0x00000000FFFF0000ULL /**< Vlan
mask. */
-#define TX_TCP_LEN_CMP_MASK 0x000000FF00000000ULL /**< TCP
header mask. */
-#define TX_TSO_MSS_CMP_MASK 0x00FFFF0000000000ULL /**< TSO
segsz mask. */

drivers/net/igc/igc_txrx.c +0 -3
-/** Mac + IP + TCP + Mss mask. */
-#define TX_TSO_CMP_MASK	\
-	(TX_MACIP_LEN_CMP_MASK | TX_TCP_LEN_CMP_MASK |

TX_TSO_MSS_CMP_MASK)

drivers/net/igc/igc_txrx.c +0 -55
-
-/**
- * Structure to check if new context need be built
- */
-struct igc_advctx_info {
-	uint64_t flags;           /**< ol_flags related to context build. */
-	/** tx offload: vlan, tso, l2-l3-l4 lengths. */
-	union igc_tx_offload tx_offload;
-	/** compare mask for tx offload. */
-	union igc_tx_offload tx_offload_mask;
-};
-
-/**
- * Hardware context number
- */
-enum {
-	IGC_CTX_0    = 0, /**< CTX0    */
-	IGC_CTX_1    = 1, /**< CTX1    */
-	IGC_CTX_NUM  = 2, /**< CTX_NUM */
-};
-
-/**
- * Structure associated with each descriptor of the TX ring of a TX queue.
- */
-struct igc_tx_entry {
-	struct rte_mbuf *mbuf; /**< mbuf associated with TX desc, if any. */
-	uint16_t next_id; /**< Index of next descriptor in ring. */
-	uint16_t last_id; /**< Index of last scattered descriptor. */
-};
-
-/**
- * Structure associated with each TX queue.
- */
-struct igc_tx_queue {
-	volatile union igc_adv_tx_desc *tx_ring; /**< TX ring address */
-	uint64_t               tx_ring_phys_addr; /**< TX ring DMA address. */
-	struct igc_tx_entry    *sw_ring; /**< virtual address of SW ring. */
-	volatile uint32_t      *tdt_reg_addr; /**< Address of TDT register. */
-	uint32_t               txd_type;      /**< Device-specific TXD type */
-	uint16_t               nb_tx_desc;    /**< number of TX descriptors. */
-	uint16_t               tx_tail;  /**< Current value of TDT register. */
-	uint16_t               tx_head;
-	/**< Index of first used TX descriptor. */
-	uint16_t               queue_id; /**< TX queue index. */
-	uint16_t               reg_idx;  /**< TX queue register index. */
-	uint16_t               port_id;  /**< Device port identifier. */
-	uint8_t                pthresh;  /**< Prefetch threshold register. */
-	uint8_t                hthresh;  /**< Host threshold register. */
-	uint8_t                wthresh;  /**< Write-back threshold register. */
-	uint8_t                ctx_curr;
-
-	/**< Start context position for transmit queue. */
-	struct igc_advctx_info ctx_cache[IGC_CTX_NUM];
-	/**< Hardware context history.*/
-	uint64_t	       offloads; /**< offloads of

RTE_ETH_TX_OFFLOAD_* */

drivers/net/igc/igc_txrx.c +0 -2
-};
-
 static inline uint64_t
 rx_desc_statuserr_to_pkt_flags(uint32_t statuserr)  { diff --git

a/drivers/net/igc/igc_txrx.h b/drivers/net/igc/igc_txrx.h index 02a0a05..5731761 100644

drivers/net/igc/igc_txrx.h +16 -0
@@ -11,6 +11,121 @@
 extern "C" {
 #endif
 
+struct igc_rx_entry {
+	struct rte_mbuf *mbuf; /**< mbuf associated with RX descriptor.
 */ };
+
+/**
+ * Structure associated with each RX queue.
+ */
+struct igc_rx_queue {
+	struct rte_mempool  *mb_pool;   /**< mbuf pool to populate RX ring.
 */
+	volatile union igc_adv_rx_desc *rx_ring;
+	/**< RX ring virtual address. */
+	uint64_t            rx_ring_phys_addr; /**< RX ring DMA address. */
+	volatile uint32_t   *rdt_reg_addr; /**< RDT register address. */
+	volatile uint32_t   *rdh_reg_addr; /**< RDH register address. */
+	struct igc_rx_entry *sw_ring;   /**< address of RX software ring. */
+	struct rte_mbuf *pkt_first_seg; /**< First segment of current packet.
 */
+	struct rte_mbuf *pkt_last_seg;  /**< Last segment of current packet.

*/

drivers/net/igc/igc_txrx.h +14 -0
+	uint16_t            nb_rx_desc; /**< number of RX descriptors. */
+	uint16_t            rx_tail;    /**< current value of RDT register. */
+	uint16_t            nb_rx_hold; /**< number of held free RX desc. */
+	uint16_t            rx_free_thresh; /**< max free RX desc to hold. */
+	uint16_t            queue_id;   /**< RX queue index. */
+	uint16_t            reg_idx;    /**< RX queue register index. */
+	uint16_t            port_id;    /**< Device port identifier. */
+	uint8_t             pthresh;    /**< Prefetch threshold register. */
+	uint8_t             hthresh;    /**< Host threshold register. */
+	uint8_t             wthresh;    /**< Write-back threshold register. */
+	uint8_t             crc_len;    /**< 0 if CRC stripped, 4 otherwise. */
+	uint8_t             drop_en;    /**< If not 0, set SRRCTL.Drop_En. */
+	uint32_t            flags;      /**< RX flags. */
+	uint64_t            offloads;   /**< offloads of RTE_ETH_RX_OFFLOAD_*

*/

drivers/net/igc/igc_txrx.h +21 -0
+};
+
+/** Offload features */
+union igc_tx_offload {
+	uint64_t data;
+	struct {
+		uint64_t l3_len:9; /**< L3 (IP) Header Length. */
+		uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
+		uint64_t vlan_tci:16;
+		/**< VLAN Tag Control Identifier(CPU order). */
+		uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */
+		uint64_t tso_segsz:16; /**< TCP TSO segment size. */
+		/* uint64_t unused:8; */
+	};
+};
+
+/**
+ * Compare mask for igc_tx_offload.data,
+ * should be in sync with igc_tx_offload layout.
+ */
+#define TX_MACIP_LEN_CMP_MASK  0x000000000000FFFFULL /**< L2L3

header mask. */
+#define TX_VLAN_CMP_MASK 0x00000000FFFF0000ULL /**< Vlan mask.
*/
+#define TX_TCP_LEN_CMP_MASK 0x000000FF00000000ULL /**< TCP
header mask. */
+#define TX_TSO_MSS_CMP_MASK 0x00FFFF0000000000ULL /**< TSO
segsz mask. */

drivers/net/igc/igc_txrx.h +3 -0
+/** Mac + IP + TCP + Mss mask. */
+#define TX_TSO_CMP_MASK        \
+	(TX_MACIP_LEN_CMP_MASK | TX_TCP_LEN_CMP_MASK |

TX_TSO_MSS_CMP_MASK)

drivers/net/igc/igc_txrx.h +53 -0
+
+/**
+ * Structure to check if new context need be built  */ struct
+igc_advctx_info {
+	uint64_t flags;           /**< ol_flags related to context build. */
+	/** tx offload: vlan, tso, l2-l3-l4 lengths. */
+	union igc_tx_offload tx_offload;
+	/** compare mask for tx offload. */
+	union igc_tx_offload tx_offload_mask;
+};
+
+/**
+ * Hardware context number
+ */
+enum {
+	IGC_CTX_0    = 0, /**< CTX0    */
+	IGC_CTX_1    = 1, /**< CTX1    */
+	IGC_CTX_NUM  = 2, /**< CTX_NUM */
+};
+
+/**
+ * Structure associated with each descriptor of the TX ring of a TX queue.
+ */
+struct igc_tx_entry {
+	struct rte_mbuf *mbuf; /**< mbuf associated with TX desc, if any. */
+	uint16_t next_id; /**< Index of next descriptor in ring. */
+	uint16_t last_id; /**< Index of last scattered descriptor. */ };
+
+/**
+ * Structure associated with each TX queue.
+ */
+struct igc_tx_queue {
+	volatile union igc_adv_tx_desc *tx_ring; /**< TX ring address */
+	uint64_t               tx_ring_phys_addr; /**< TX ring DMA address. */
+	struct igc_tx_entry    *sw_ring; /**< virtual address of SW ring. */
+	volatile uint32_t      *tdt_reg_addr; /**< Address of TDT register. */
+	uint32_t               txd_type;      /**< Device-specific TXD type */
+	uint16_t               nb_tx_desc;    /**< number of TX descriptors. */
+	uint16_t               tx_tail;  /**< Current value of TDT register. */
+	uint16_t               tx_head;
+	/**< Index of first used TX descriptor. */
+	uint16_t               queue_id; /**< TX queue index. */
+	uint16_t               reg_idx;  /**< TX queue register index. */
+	uint16_t               port_id;  /**< Device port identifier. */
+	uint8_t                pthresh;  /**< Prefetch threshold register. */
+	uint8_t                hthresh;  /**< Host threshold register. */
+	uint8_t                wthresh;  /**< Write-back threshold register. */
+	uint8_t                ctx_curr;
+
+	/**< Start context position for transmit queue. */
+	struct igc_advctx_info ctx_cache[IGC_CTX_NUM];
+	/**< Hardware context history.*/
+	uint64_t               offloads; /**< offloads of RTE_ETH_TX_OFFLOAD_*

*/

drivers/net/igc/igc_txrx.h +2 -1
+};
+
 /*
  * RX/TX function prototypes
  */
--

2.9.5

author
#3 lore raw

RE: [PATCH 1/3] net/igc: code refactoring

Hi Qi,

Quoted 18 lines

-----Original Message-----
From: Zhang, Qi Z <[email protected]>
Sent: Tuesday, January 17, 2023 10:25 AM
To: Su, Simei <[email protected]>; Guo, Junfeng <[email protected]>
Cc: [email protected]; Wu, Wenjun1 <[email protected]>
Subject: RE: [PATCH 1/3] net/igc: code refactoring

Quoted 9 lines

-----Original Message-----
From: Su, Simei <[email protected]>
Sent: Tuesday, December 20, 2022 11:41 AM
To: Zhang, Qi Z <[email protected]>; Guo, Junfeng <[email protected]>
Cc: [email protected]; Wu, Wenjun1 <[email protected]>; Su, Simei <[email protected]>
Subject: [PATCH 1/3] net/igc: code refactoring

Quoted 6 lines
Quoted 2 lines

Move related structures for Rx/Tx queue from igc_txrx.c to igc_txrx.h to make code cleaner and variables used more conveniently.

Not sure if this is necessary.
If a structure only be used internally, keep it internally should be OK. Otherwise need to give a reason why to expose it.

OK. I will rework commit log to give detailed reason in v2.

Thanks,
Simei

Quoted 296 lines
Quoted 116 lines
---
 drivers/net/igc/igc_txrx.c | 118
---------------------------------------------
 drivers/net/igc/igc_txrx.h | 115
+++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 118 deletions(-)
drivers/net/igc/igc_txrx.c +0 -0

index
ffd219b..c462e91 100644

drivers/net/igc/igc_txrx.c +0 -20
@@ -93,124 +93,6 @@
 
 #define IGC_TX_OFFLOAD_NOTSUP_MASK
 (RTE_MBUF_F_TX_OFFLOAD_MASK ^ IGC_TX_OFFLOAD_MASK)
 
-/**
- * Structure associated with each descriptor of the RX ring of a RX queue.
- */
-struct igc_rx_entry {
-	struct rte_mbuf *mbuf; /**< mbuf associated with RX descriptor. */
-};
-
-/**
- * Structure associated with each RX queue.
- */
-struct igc_rx_queue {
-	struct rte_mempool  *mb_pool;   /**< mbuf pool to populate RX ring.
 */
-	volatile union igc_adv_rx_desc *rx_ring;
-	/**< RX ring virtual address. */
-	uint64_t            rx_ring_phys_addr; /**< RX ring DMA address. */
-	volatile uint32_t   *rdt_reg_addr; /**< RDT register address. */
-	volatile uint32_t   *rdh_reg_addr; /**< RDH register address. */
-	struct igc_rx_entry *sw_ring;   /**< address of RX software ring. */
-	struct rte_mbuf *pkt_first_seg; /**< First segment of current packet.
 */
-	struct rte_mbuf *pkt_last_seg;  /**< Last segment of current packet.

*/

drivers/net/igc/igc_txrx.c +0 -14
-	uint16_t            nb_rx_desc; /**< number of RX descriptors. */
-	uint16_t            rx_tail;    /**< current value of RDT register. */
-	uint16_t            nb_rx_hold; /**< number of held free RX desc. */
-	uint16_t            rx_free_thresh; /**< max free RX desc to hold. */
-	uint16_t            queue_id;   /**< RX queue index. */
-	uint16_t            reg_idx;    /**< RX queue register index. */
-	uint16_t            port_id;    /**< Device port identifier. */
-	uint8_t             pthresh;    /**< Prefetch threshold register. */
-	uint8_t             hthresh;    /**< Host threshold register. */
-	uint8_t             wthresh;    /**< Write-back threshold register. */
-	uint8_t             crc_len;    /**< 0 if CRC stripped, 4 otherwise. */
-	uint8_t             drop_en;	/**< If not 0, set SRRCTL.Drop_En. */
-	uint32_t            flags;      /**< RX flags. */
-	uint64_t	    offloads;   /**< offloads of

RTE_ETH_RX_OFFLOAD_* */

drivers/net/igc/igc_txrx.c +0 -21
-};
-
-/** Offload features */
-union igc_tx_offload {
-	uint64_t data;
-	struct {
-		uint64_t l3_len:9; /**< L3 (IP) Header Length. */
-		uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
-		uint64_t vlan_tci:16;
-		/**< VLAN Tag Control Identifier(CPU order). */
-		uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */
-		uint64_t tso_segsz:16; /**< TCP TSO segment size. */
-		/* uint64_t unused:8; */
-	};
-};
-
-/*
- * Compare mask for igc_tx_offload.data,
- * should be in sync with igc_tx_offload layout.
- */
-#define TX_MACIP_LEN_CMP_MASK	0x000000000000FFFFULL /**< L2L3

header mask. */
-#define TX_VLAN_CMP_MASK 0x00000000FFFF0000ULL /**< Vlan
mask. */
-#define TX_TCP_LEN_CMP_MASK 0x000000FF00000000ULL /**< TCP
header mask. */
-#define TX_TSO_MSS_CMP_MASK 0x00FFFF0000000000ULL /**< TSO
segsz mask. */

drivers/net/igc/igc_txrx.c +0 -3
-/** Mac + IP + TCP + Mss mask. */
-#define TX_TSO_CMP_MASK	\
-	(TX_MACIP_LEN_CMP_MASK | TX_TCP_LEN_CMP_MASK |

TX_TSO_MSS_CMP_MASK)

drivers/net/igc/igc_txrx.c +0 -26
-
-/**
- * Structure to check if new context need be built
- */
-struct igc_advctx_info {
-	uint64_t flags;           /**< ol_flags related to context build. */
-	/** tx offload: vlan, tso, l2-l3-l4 lengths. */
-	union igc_tx_offload tx_offload;
-	/** compare mask for tx offload. */
-	union igc_tx_offload tx_offload_mask;
-};
-
-/**
- * Hardware context number
- */
-enum {
-	IGC_CTX_0    = 0, /**< CTX0    */
-	IGC_CTX_1    = 1, /**< CTX1    */
-	IGC_CTX_NUM  = 2, /**< CTX_NUM */
-};
-
-/**
- * Structure associated with each descriptor of the TX ring of a TX queue.
- */
-struct igc_tx_entry {
-	struct rte_mbuf *mbuf; /**< mbuf associated with TX desc, if any. */

drivers/net/igc/igc_txrx.c

Quoted 10 lines
drivers/net/igc/igc_txrx.c +0 -10
-	uint16_t next_id; /**< Index of next descriptor in ring. */
-	uint16_t last_id; /**< Index of last scattered descriptor. */
-};
-
-/**
- * Structure associated with each TX queue.
- */
-struct igc_tx_queue {
-	volatile union igc_adv_tx_desc *tx_ring; /**< TX ring address */
-	uint64_t               tx_ring_phys_addr; /**< TX ring DMA address.

*/

drivers/net/igc/igc_txrx.c

Quoted 3 lines
drivers/net/igc/igc_txrx.c +0 -3
-	struct igc_tx_entry    *sw_ring; /**< virtual address of SW ring. */
-	volatile uint32_t      *tdt_reg_addr; /**< Address of TDT register. */
-	uint32_t               txd_type;      /**< Device-specific TXD type

*/

drivers/net/igc/igc_txrx.c

Quoted 1 line
drivers/net/igc/igc_txrx.c +0 -1
-	uint16_t               nb_tx_desc;    /**< number of TX descriptors.

*/

drivers/net/igc/igc_txrx.c

Quoted 9 lines
drivers/net/igc/igc_txrx.c +0 -9
-	uint16_t               tx_tail;  /**< Current value of TDT register. */
-	uint16_t               tx_head;
-	/**< Index of first used TX descriptor. */
-	uint16_t               queue_id; /**< TX queue index. */
-	uint16_t               reg_idx;  /**< TX queue register index. */
-	uint16_t               port_id;  /**< Device port identifier. */
-	uint8_t                pthresh;  /**< Prefetch threshold register. */
-	uint8_t                hthresh;  /**< Host threshold register. */
-	uint8_t                wthresh;  /**< Write-back threshold register.

*/

Quoted 43 lines
drivers/net/igc/igc_txrx.c +0 -6
-	uint8_t                ctx_curr;
-
-	/**< Start context position for transmit queue. */
-	struct igc_advctx_info ctx_cache[IGC_CTX_NUM];
-	/**< Hardware context history.*/
-	uint64_t	       offloads; /**< offloads of

RTE_ETH_TX_OFFLOAD_* */

drivers/net/igc/igc_txrx.c +0 -2
-};
-
 static inline uint64_t
 rx_desc_statuserr_to_pkt_flags(uint32_t statuserr)  { diff --git

a/drivers/net/igc/igc_txrx.h b/drivers/net/igc/igc_txrx.h index 02a0a05..5731761 100644

drivers/net/igc/igc_txrx.h +16 -0
@@ -11,6 +11,121 @@
 extern "C" {
 #endif
 
+struct igc_rx_entry {
+	struct rte_mbuf *mbuf; /**< mbuf associated with RX descriptor.
 */ };
+
+/**
+ * Structure associated with each RX queue.
+ */
+struct igc_rx_queue {
+	struct rte_mempool  *mb_pool;   /**< mbuf pool to populate RX ring.
 */
+	volatile union igc_adv_rx_desc *rx_ring;
+	/**< RX ring virtual address. */
+	uint64_t            rx_ring_phys_addr; /**< RX ring DMA address. */
+	volatile uint32_t   *rdt_reg_addr; /**< RDT register address. */
+	volatile uint32_t   *rdh_reg_addr; /**< RDH register address. */
+	struct igc_rx_entry *sw_ring;   /**< address of RX software ring. */
+	struct rte_mbuf *pkt_first_seg; /**< First segment of current packet.
 */
+	struct rte_mbuf *pkt_last_seg;  /**< Last segment of current packet.

*/

drivers/net/igc/igc_txrx.h +4 -0
+	uint16_t            nb_rx_desc; /**< number of RX descriptors. */
+	uint16_t            rx_tail;    /**< current value of RDT register. */
+	uint16_t            nb_rx_hold; /**< number of held free RX desc. */
+	uint16_t            rx_free_thresh; /**< max free RX desc to hold. */

drivers/net/igc/igc_txrx.h

Quoted 10 lines
drivers/net/igc/igc_txrx.h +10 -0
+	uint16_t            queue_id;   /**< RX queue index. */
+	uint16_t            reg_idx;    /**< RX queue register index. */
+	uint16_t            port_id;    /**< Device port identifier. */
+	uint8_t             pthresh;    /**< Prefetch threshold register. */
+	uint8_t             hthresh;    /**< Host threshold register. */
+	uint8_t             wthresh;    /**< Write-back threshold register. */
+	uint8_t             crc_len;    /**< 0 if CRC stripped, 4 otherwise. */
+	uint8_t             drop_en;    /**< If not 0, set SRRCTL.Drop_En. */
+	uint32_t            flags;      /**< RX flags. */
+	uint64_t            offloads;   /**< offloads of

RTE_ETH_RX_OFFLOAD_*

Quoted 22 lines

*/

drivers/net/igc/igc_txrx.h +21 -0
+};
+
+/** Offload features */
+union igc_tx_offload {
+	uint64_t data;
+	struct {
+		uint64_t l3_len:9; /**< L3 (IP) Header Length. */
+		uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
+		uint64_t vlan_tci:16;
+		/**< VLAN Tag Control Identifier(CPU order). */
+		uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */
+		uint64_t tso_segsz:16; /**< TCP TSO segment size. */
+		/* uint64_t unused:8; */
+	};
+};
+
+/**
+ * Compare mask for igc_tx_offload.data,
+ * should be in sync with igc_tx_offload layout.
+ */
+#define TX_MACIP_LEN_CMP_MASK  0x000000000000FFFFULL /**< L2L3
Quoted 2 lines

header mask. */
+#define TX_VLAN_CMP_MASK 0x00000000FFFF0000ULL /**< Vlan

mask.

Quoted 32 lines

*/
+#define TX_TCP_LEN_CMP_MASK 0x000000FF00000000ULL /**< TCP
header mask. */
+#define TX_TSO_MSS_CMP_MASK 0x00FFFF0000000000ULL /**< TSO
segsz mask. */

drivers/net/igc/igc_txrx.h +3 -0
+/** Mac + IP + TCP + Mss mask. */
+#define TX_TSO_CMP_MASK        \
+	(TX_MACIP_LEN_CMP_MASK | TX_TCP_LEN_CMP_MASK |

TX_TSO_MSS_CMP_MASK)

drivers/net/igc/igc_txrx.h +23 -0
+
+/**
+ * Structure to check if new context need be built  */ struct
+igc_advctx_info {
+	uint64_t flags;           /**< ol_flags related to context build. */
+	/** tx offload: vlan, tso, l2-l3-l4 lengths. */
+	union igc_tx_offload tx_offload;
+	/** compare mask for tx offload. */
+	union igc_tx_offload tx_offload_mask; };
+
+/**
+ * Hardware context number
+ */
+enum {
+	IGC_CTX_0    = 0, /**< CTX0    */
+	IGC_CTX_1    = 1, /**< CTX1    */
+	IGC_CTX_NUM  = 2, /**< CTX_NUM */
+};
+
+/**
+ * Structure associated with each descriptor of the TX ring of a TX queue.
+ */
+struct igc_tx_entry {

drivers/net/igc/igc_txrx.h

Quoted 10 lines
drivers/net/igc/igc_txrx.h +10 -0
+	struct rte_mbuf *mbuf; /**< mbuf associated with TX desc, if any. */
+	uint16_t next_id; /**< Index of next descriptor in ring. */
+	uint16_t last_id; /**< Index of last scattered descriptor. */ };
+
+/**
+ * Structure associated with each TX queue.
+ */
+struct igc_tx_queue {
+	volatile union igc_adv_tx_desc *tx_ring; /**< TX ring address */
+	uint64_t               tx_ring_phys_addr; /**< TX ring DMA address.

*/

drivers/net/igc/igc_txrx.h

Quoted 3 lines
drivers/net/igc/igc_txrx.h +3 -0
+	struct igc_tx_entry    *sw_ring; /**< virtual address of SW ring. */
+	volatile uint32_t      *tdt_reg_addr; /**< Address of TDT register. */
+	uint32_t               txd_type;      /**< Device-specific TXD type

*/

drivers/net/igc/igc_txrx.h

Quoted 1 line
drivers/net/igc/igc_txrx.h +1 -0
+	uint16_t               nb_tx_desc;    /**< number of TX descriptors.

*/

drivers/net/igc/igc_txrx.h

Quoted 9 lines
drivers/net/igc/igc_txrx.h +9 -0
+	uint16_t               tx_tail;  /**< Current value of TDT register. */
+	uint16_t               tx_head;
+	/**< Index of first used TX descriptor. */
+	uint16_t               queue_id; /**< TX queue index. */
+	uint16_t               reg_idx;  /**< TX queue register index. */
+	uint16_t               port_id;  /**< Device port identifier. */
+	uint8_t                pthresh;  /**< Prefetch threshold register. */
+	uint8_t                hthresh;  /**< Host threshold register. */
+	uint8_t                wthresh;  /**< Write-back threshold register.

*/

drivers/net/igc/igc_txrx.h

Quoted 6 lines
drivers/net/igc/igc_txrx.h +6 -0
+	uint8_t                ctx_curr;
+
+	/**< Start context position for transmit queue. */
+	struct igc_advctx_info ctx_cache[IGC_CTX_NUM];
+	/**< Hardware context history.*/
+	uint64_t               offloads; /**< offloads of

RTE_ETH_TX_OFFLOAD_*

Quoted 8 lines

*/

drivers/net/igc/igc_txrx.h +2 -1
+};
+
 /*
  * RX/TX function prototypes
  */
--

2.9.5

author
#4 lore raw

PATCH 2/3 net/igc/base: support PTP timesync

In reply to Simei Su

Add definitions for timesync enabling.

---
 drivers/net/igc/base/igc_defines.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/igc/base/igc_defines.h +11 -0
index 61964bc..dd7330a 100644
@@ -795,6 +795,17 @@
 
 #define TSYNC_INTERRUPTS	TSINTR_TXTS
 
+/* Split Replication Receive Control */
+#define IGC_SRRCTL_TIMESTAMP           0x40000000
+#define IGC_SRRCTL_TIMER1SEL(timer)    (((timer) & 0x3) << 14)
+#define IGC_SRRCTL_TIMER0SEL(timer)    (((timer) & 0x3) << 17)
+
+/* Sample RX tstamp in PHY sop */
+#define IGC_TSYNCRXCTL_RXSYNSIG         0x00000400
+
+/* Sample TX tstamp in PHY sop */
+#define IGC_TSYNCTXCTL_TXSYNSIG         0x00000020
+
 /* TSAUXC Configuration Bits */
 #define TSAUXC_EN_TT0	(1 << 0)  /* Enable target time 0. */
 #define TSAUXC_EN_TT1	(1 << 1)  /* Enable target time 1. */
Signature · 1 line
2.9.5
author
#5 lore raw

PATCH 3/3 net/igc: support IEEE 1588 PTP

In reply to Simei Su

Add igc support for new ethdev APIs to enable/disable and read/write/adjust IEEE1588 PTP timestamps.

The example command for running ptpclient is as below:
./build/examples/dpdk-ptpclient -c 1 -n 3 -- -T 0 -p 0x1

---
 drivers/net/igc/igc_ethdev.c | 222 +++++++++++++++++++++++++++++++++++++++++++
 drivers/net/igc/igc_ethdev.h |   4 +-
 drivers/net/igc/igc_txrx.c   |  50 +++++++++-
 drivers/net/igc/igc_txrx.h   |   1 +
 4 files changed, 272 insertions(+), 5 deletions(-)
drivers/net/igc/igc_ethdev.c +222 -0
index dcd262f..ef3346b 100644
@@ -78,6 +78,16 @@
 #define IGC_ALARM_INTERVAL	8000000u
 /* us, about 13.6s some per-queue registers will wrap around back to 0. */
 
+/* Transmit and receive latency (for PTP timestamps) */
+#define IGC_I225_TX_LATENCY_10		240
+#define IGC_I225_TX_LATENCY_100		58
+#define IGC_I225_TX_LATENCY_1000	80
+#define IGC_I225_TX_LATENCY_2500	1325
+#define IGC_I225_RX_LATENCY_10		6450
+#define IGC_I225_RX_LATENCY_100		185
+#define IGC_I225_RX_LATENCY_1000	300
+#define IGC_I225_RX_LATENCY_2500	1485
+
 static const struct rte_eth_desc_lim rx_desc_lim = {
 	.nb_max = IGC_MAX_RXD,
 	.nb_min = IGC_MIN_RXD,
@@ -245,6 +255,18 @@ eth_igc_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
 static int eth_igc_vlan_offload_set(struct rte_eth_dev *dev, int mask);
 static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,
 		      enum rte_vlan_type vlan_type, uint16_t tpid);
+static int eth_igc_timesync_enable(struct rte_eth_dev *dev);
+static int eth_igc_timesync_disable(struct rte_eth_dev *dev);
+static int eth_igc_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
+					  struct timespec *timestamp,
+					  uint32_t flags);
+static int eth_igc_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
+					  struct timespec *timestamp);
+static int eth_igc_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
+static int eth_igc_timesync_read_time(struct rte_eth_dev *dev,
+				  struct timespec *timestamp);
+static int eth_igc_timesync_write_time(struct rte_eth_dev *dev,
+				   const struct timespec *timestamp);
 
 static const struct eth_dev_ops eth_igc_ops = {
 	.dev_configure		= eth_igc_configure,
@@ -298,6 +320,13 @@ static const struct eth_dev_ops eth_igc_ops = {
 	.vlan_tpid_set		= eth_igc_vlan_tpid_set,
 	.vlan_strip_queue_set	= eth_igc_vlan_strip_queue_set,
 	.flow_ops_get		= eth_igc_flow_ops_get,
+	.timesync_enable	= eth_igc_timesync_enable,
+	.timesync_disable	= eth_igc_timesync_disable,
+	.timesync_read_rx_timestamp = eth_igc_timesync_read_rx_timestamp,
+	.timesync_read_tx_timestamp = eth_igc_timesync_read_tx_timestamp,
+	.timesync_adjust_time	= eth_igc_timesync_adjust_time,
+	.timesync_read_time	= eth_igc_timesync_read_time,
+	.timesync_write_time	= eth_igc_timesync_write_time,
 };
 
 /*
@@ -2582,6 +2611,199 @@ eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,
 }
 
 static int
+eth_igc_timesync_enable(struct rte_eth_dev *dev)
+{
+	struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
+	struct timespec system_time;
+	struct igc_rx_queue *rxq;
+	uint32_t val;
+	uint16_t i;
+
+	IGC_WRITE_REG(hw, IGC_TSAUXC, 0x0);
+
+	clock_gettime(CLOCK_REALTIME, &system_time);
+	IGC_WRITE_REG(hw, IGC_SYSTIML, system_time.tv_nsec);
+	IGC_WRITE_REG(hw, IGC_SYSTIMH, system_time.tv_sec);
+
+	/* Enable timestamping of received PTP packets. */
+	val = IGC_READ_REG(hw, IGC_RXPBS);
+	val |= IGC_RXPBS_CFG_TS_EN;
+	IGC_WRITE_REG(hw, IGC_RXPBS, val);
+
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		val = IGC_READ_REG(hw, IGC_SRRCTL(i));
+		/* For now, only support retrieving Rx timestamp from timer0. */
+		val |= IGC_SRRCTL_TIMER1SEL(0) | IGC_SRRCTL_TIMER0SEL(0) |
+		       IGC_SRRCTL_TIMESTAMP;
+		IGC_WRITE_REG(hw, IGC_SRRCTL(i), val);
+	}
+
+	val = IGC_TSYNCRXCTL_ENABLED | IGC_TSYNCRXCTL_TYPE_ALL |
+	      IGC_TSYNCRXCTL_RXSYNSIG;
+	IGC_WRITE_REG(hw, IGC_TSYNCRXCTL, val);
+
+	/* Enable Timestamping of transmitted PTP packets. */
+	IGC_WRITE_REG(hw, IGC_TSYNCTXCTL, IGC_TSYNCTXCTL_ENABLED |
+		      IGC_TSYNCTXCTL_TXSYNSIG);
+
+	/* Read TXSTMP registers to discard any timestamp previously stored. */
+	IGC_READ_REG(hw, IGC_TXSTMPL);
+	IGC_READ_REG(hw, IGC_TXSTMPH);
+
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		rxq = dev->data->rx_queues[i];
+		rxq->offloads |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
+	}
+
+	return 0;
+}
+
+static int
+eth_igc_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
+{
+	struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
+
+	ts->tv_nsec = IGC_READ_REG(hw, IGC_SYSTIML);
+	ts->tv_sec = IGC_READ_REG(hw, IGC_SYSTIMH);
+
+	return 0;
+}
+
+static int
+eth_igc_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
+{
+	struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
+
+	IGC_WRITE_REG(hw, IGC_SYSTIML, ts->tv_nsec);
+	IGC_WRITE_REG(hw, IGC_SYSTIMH, ts->tv_sec);
+
+	return 0;
+}
+
+static int
+eth_igc_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
+{
+	struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
+	uint32_t nsec, sec;
+	uint64_t systime, ns;
+	struct timespec ts;
+
+	nsec = (uint64_t)IGC_READ_REG(hw, IGC_SYSTIML);
+	sec = (uint64_t)IGC_READ_REG(hw, IGC_SYSTIMH);
+	systime = sec * NSEC_PER_SEC + nsec;
+
+	ns = systime + delta;
+	ts = rte_ns_to_timespec(ns);
+
+	IGC_WRITE_REG(hw, IGC_SYSTIML, ts.tv_nsec);
+	IGC_WRITE_REG(hw, IGC_SYSTIMH, ts.tv_sec);
+
+	return 0;
+}
+
+static int
+eth_igc_timesync_read_rx_timestamp(__rte_unused struct rte_eth_dev *dev,
+			       struct timespec *timestamp,
+			       uint32_t flags)
+{
+	struct rte_eth_link link;
+	int adjust = 0;
+	struct igc_rx_queue *rxq;
+	uint64_t rx_timestamp;
+
+	/* Get current link speed. */
+	eth_igc_link_update(dev, 1);
+	rte_eth_linkstatus_get(dev, &link);
+
+	switch (link.link_speed) {
+	case SPEED_10:
+		adjust = IGC_I225_RX_LATENCY_10;
+		break;
+	case SPEED_100:
+		adjust = IGC_I225_RX_LATENCY_100;
+		break;
+	case SPEED_1000:
+		adjust = IGC_I225_RX_LATENCY_1000;
+		break;
+	case SPEED_2500:
+		adjust = IGC_I225_RX_LATENCY_2500;
+		break;
+	}
+
+	rxq = dev->data->rx_queues[flags];
+	rx_timestamp = rxq->rx_timestamp - adjust;
+	*timestamp = rte_ns_to_timespec(rx_timestamp);
+
+	return 0;
+}
+
+static int
+eth_igc_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
+			       struct timespec *timestamp)
+{
+	struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
+	struct rte_eth_link link;
+	uint32_t val, nsec, sec;
+	uint64_t tx_timestamp;
+	int adjust = 0;
+
+	val = IGC_READ_REG(hw, IGC_TSYNCTXCTL);
+	if (!(val & IGC_TSYNCTXCTL_VALID))
+		return -EINVAL;
+
+	nsec = (uint64_t)IGC_READ_REG(hw, IGC_TXSTMPL);
+	sec = (uint64_t)IGC_READ_REG(hw, IGC_TXSTMPH);
+	tx_timestamp = sec * NSEC_PER_SEC + nsec;
+
+	/* Get current link speed. */
+	eth_igc_link_update(dev, 1);
+	rte_eth_linkstatus_get(dev, &link);
+
+	switch (link.link_speed) {
+	case SPEED_10:
+		adjust = IGC_I225_TX_LATENCY_10;
+		break;
+	case SPEED_100:
+		adjust = IGC_I225_TX_LATENCY_100;
+		break;
+	case SPEED_1000:
+		adjust = IGC_I225_TX_LATENCY_1000;
+		break;
+	case SPEED_2500:
+		adjust = IGC_I225_TX_LATENCY_2500;
+		break;
+	}
+
+	tx_timestamp += adjust;
+	*timestamp = rte_ns_to_timespec(tx_timestamp);
+
+	return 0;
+}
+
+static int
+eth_igc_timesync_disable(struct rte_eth_dev *dev)
+{
+	struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
+	uint32_t val;
+
+	/* Disable timestamping of transmitted PTP packets. */
+	IGC_WRITE_REG(hw, IGC_TSYNCTXCTL, 0);
+
+	/* Disable timestamping of received PTP packets. */
+	IGC_WRITE_REG(hw, IGC_TSYNCRXCTL, 0);
+
+	val = IGC_READ_REG(hw, IGC_RXPBS);
+	val &= IGC_RXPBS_CFG_TS_EN;
+	IGC_WRITE_REG(hw, IGC_RXPBS, val);
+
+	val = IGC_READ_REG(hw, IGC_SRRCTL(0));
+	val &= ~IGC_SRRCTL_TIMESTAMP;
+	IGC_WRITE_REG(hw, IGC_SRRCTL(0), val);
+
+	return 0;
+}
+
+static int
 eth_igc_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	struct rte_pci_device *pci_dev)
 {
drivers/net/igc/igc_ethdev.h +3 -1
index f56cad7..237d3c1 100644
@@ -7,6 +7,7 @@
 
 #include <rte_ethdev.h>
 #include <rte_flow.h>
+#include <rte_time.h>
 
 #include "base/igc_osdep.h"
 #include "base/igc_hw.h"
@@ -75,7 +76,8 @@ extern "C" {
 	RTE_ETH_RX_OFFLOAD_SCTP_CKSUM  | \
 	RTE_ETH_RX_OFFLOAD_KEEP_CRC    | \
 	RTE_ETH_RX_OFFLOAD_SCATTER     | \
-	RTE_ETH_RX_OFFLOAD_RSS_HASH)
+	RTE_ETH_RX_OFFLOAD_RSS_HASH    | \
+	RTE_ETH_RX_OFFLOAD_TIMESTAMP)
 
 #define IGC_TX_OFFLOAD_ALL	(    \
 	RTE_ETH_TX_OFFLOAD_VLAN_INSERT | \
drivers/net/igc/igc_txrx.c +46 -4

106 lines not on this page · raw message

drivers/net/igc/igc_txrx.h +1 -0
index 5731761..e7272f8 100644
@@ -42,6 +42,7 @@ struct igc_rx_queue {
 	uint8_t             drop_en;    /**< If not 0, set SRRCTL.Drop_En. */
 	uint32_t            flags;      /**< RX flags. */
 	uint64_t            offloads;   /**< offloads of RTE_ETH_RX_OFFLOAD_* */
+	uint64_t            rx_timestamp;
 };
 
 /** Offload features */
Signature · 1 line
2.9.5
author
#6 lore raw

v2 cover net/igc: support PTP timesync

In reply to Simei Su

[PATCH v2 1/3] code refactoring.
[PATCH v2 2/3] add related definitions for ptp timesync. [PATCH v2 3/3] add IEEE1588 API to support timesync.

v2:
* Refine commit log.
* Update the doc/guides/nics/features/igc.ini to add "Timesync" feature.
* Add release notes.

Simei Su (3):
net/igc: code refactoring
net/igc/base: support PTP timesync
net/igc: support IEEE 1588 PTP

 doc/guides/nics/features/igc.ini       |   1 +
 doc/guides/rel_notes/release_23_03.rst |   3 +
 drivers/net/igc/base/igc_defines.h     |  11 ++
 drivers/net/igc/igc_ethdev.c           | 222 +++++++++++++++++++++++++++++++++
 drivers/net/igc/igc_ethdev.h           |   4 +-
 drivers/net/igc/igc_txrx.c             | 166 +++++++-----------------
 drivers/net/igc/igc_txrx.h             | 116 +++++++++++++++++
 7 files changed, 401 insertions(+), 122 deletions(-)
Signature · 1 line
2.9.5
author
#7 lore raw

PATCH v2 1/3 net/igc: code refactoring

This patch moves some structures from rxtx.c to rxtx.h for the timesync enabling feature. For example, variables in "igc_rx_queue" structure can be used by variables both in igc_ethdev.c and igc_txrx.c more conveniently. It is also consistent with other PMD coding styles.

---
 drivers/net/igc/igc_txrx.c | 118 ---------------------------------------------
 drivers/net/igc/igc_txrx.h | 115 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 118 deletions(-)
drivers/net/igc/igc_txrx.c +0 -118
index ffd219b..c462e91 100644
@@ -93,124 +93,6 @@
 
 #define IGC_TX_OFFLOAD_NOTSUP_MASK (RTE_MBUF_F_TX_OFFLOAD_MASK ^ IGC_TX_OFFLOAD_MASK)
 
-/**
- * Structure associated with each descriptor of the RX ring of a RX queue.
- */
-struct igc_rx_entry {
-	struct rte_mbuf *mbuf; /**< mbuf associated with RX descriptor. */
-};
-
-/**
- * Structure associated with each RX queue.
- */
-struct igc_rx_queue {
-	struct rte_mempool  *mb_pool;   /**< mbuf pool to populate RX ring. */
-	volatile union igc_adv_rx_desc *rx_ring;
-	/**< RX ring virtual address. */
-	uint64_t            rx_ring_phys_addr; /**< RX ring DMA address. */
-	volatile uint32_t   *rdt_reg_addr; /**< RDT register address. */
-	volatile uint32_t   *rdh_reg_addr; /**< RDH register address. */
-	struct igc_rx_entry *sw_ring;   /**< address of RX software ring. */
-	struct rte_mbuf *pkt_first_seg; /**< First segment of current packet. */
-	struct rte_mbuf *pkt_last_seg;  /**< Last segment of current packet. */
-	uint16_t            nb_rx_desc; /**< number of RX descriptors. */
-	uint16_t            rx_tail;    /**< current value of RDT register. */
-	uint16_t            nb_rx_hold; /**< number of held free RX desc. */
-	uint16_t            rx_free_thresh; /**< max free RX desc to hold. */
-	uint16_t            queue_id;   /**< RX queue index. */
-	uint16_t            reg_idx;    /**< RX queue register index. */
-	uint16_t            port_id;    /**< Device port identifier. */
-	uint8_t             pthresh;    /**< Prefetch threshold register. */
-	uint8_t             hthresh;    /**< Host threshold register. */
-	uint8_t             wthresh;    /**< Write-back threshold register. */
-	uint8_t             crc_len;    /**< 0 if CRC stripped, 4 otherwise. */
-	uint8_t             drop_en;	/**< If not 0, set SRRCTL.Drop_En. */
-	uint32_t            flags;      /**< RX flags. */
-	uint64_t	    offloads;   /**< offloads of RTE_ETH_RX_OFFLOAD_* */
-};
-
-/** Offload features */
-union igc_tx_offload {
-	uint64_t data;
-	struct {
-		uint64_t l3_len:9; /**< L3 (IP) Header Length. */
-		uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
-		uint64_t vlan_tci:16;
-		/**< VLAN Tag Control Identifier(CPU order). */
-		uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */
-		uint64_t tso_segsz:16; /**< TCP TSO segment size. */
-		/* uint64_t unused:8; */
-	};
-};
-
-/*
- * Compare mask for igc_tx_offload.data,
- * should be in sync with igc_tx_offload layout.
- */
-#define TX_MACIP_LEN_CMP_MASK	0x000000000000FFFFULL /**< L2L3 header mask. */
-#define TX_VLAN_CMP_MASK	0x00000000FFFF0000ULL /**< Vlan mask. */
-#define TX_TCP_LEN_CMP_MASK	0x000000FF00000000ULL /**< TCP header mask. */
-#define TX_TSO_MSS_CMP_MASK	0x00FFFF0000000000ULL /**< TSO segsz mask. */
-/** Mac + IP + TCP + Mss mask. */
-#define TX_TSO_CMP_MASK	\
-	(TX_MACIP_LEN_CMP_MASK | TX_TCP_LEN_CMP_MASK | TX_TSO_MSS_CMP_MASK)
-
-/**
- * Structure to check if new context need be built
- */
-struct igc_advctx_info {
-	uint64_t flags;           /**< ol_flags related to context build. */
-	/** tx offload: vlan, tso, l2-l3-l4 lengths. */
-	union igc_tx_offload tx_offload;
-	/** compare mask for tx offload. */
-	union igc_tx_offload tx_offload_mask;
-};
-
-/**
- * Hardware context number
- */
-enum {
-	IGC_CTX_0    = 0, /**< CTX0    */
-	IGC_CTX_1    = 1, /**< CTX1    */
-	IGC_CTX_NUM  = 2, /**< CTX_NUM */
-};
-
-/**
- * Structure associated with each descriptor of the TX ring of a TX queue.
- */
-struct igc_tx_entry {
-	struct rte_mbuf *mbuf; /**< mbuf associated with TX desc, if any. */
-	uint16_t next_id; /**< Index of next descriptor in ring. */
-	uint16_t last_id; /**< Index of last scattered descriptor. */
-};
-
-/**
- * Structure associated with each TX queue.
- */
-struct igc_tx_queue {
-	volatile union igc_adv_tx_desc *tx_ring; /**< TX ring address */
-	uint64_t               tx_ring_phys_addr; /**< TX ring DMA address. */
-	struct igc_tx_entry    *sw_ring; /**< virtual address of SW ring. */
-	volatile uint32_t      *tdt_reg_addr; /**< Address of TDT register. */
-	uint32_t               txd_type;      /**< Device-specific TXD type */
-	uint16_t               nb_tx_desc;    /**< number of TX descriptors. */
-	uint16_t               tx_tail;  /**< Current value of TDT register. */
-	uint16_t               tx_head;
-	/**< Index of first used TX descriptor. */
-	uint16_t               queue_id; /**< TX queue index. */
-	uint16_t               reg_idx;  /**< TX queue register index. */
-	uint16_t               port_id;  /**< Device port identifier. */
-	uint8_t                pthresh;  /**< Prefetch threshold register. */
-	uint8_t                hthresh;  /**< Host threshold register. */
-	uint8_t                wthresh;  /**< Write-back threshold register. */
-	uint8_t                ctx_curr;
-
-	/**< Start context position for transmit queue. */
-	struct igc_advctx_info ctx_cache[IGC_CTX_NUM];
-	/**< Hardware context history.*/
-	uint64_t	       offloads; /**< offloads of RTE_ETH_TX_OFFLOAD_* */
-};
-
 static inline uint64_t
 rx_desc_statuserr_to_pkt_flags(uint32_t statuserr)
 {
drivers/net/igc/igc_txrx.h +115 -0

121 lines not on this page · raw message

Signature · 1 line
2.9.5
author
#8 lore raw

PATCH v2 2/3 net/igc/base: support PTP timesync

In reply to Simei Su

Add definitions for timesync enabling.

---
 drivers/net/igc/base/igc_defines.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/igc/base/igc_defines.h +11 -0
index 61964bc..dd7330a 100644
@@ -795,6 +795,17 @@
 
 #define TSYNC_INTERRUPTS	TSINTR_TXTS
 
+/* Split Replication Receive Control */
+#define IGC_SRRCTL_TIMESTAMP           0x40000000
+#define IGC_SRRCTL_TIMER1SEL(timer)    (((timer) & 0x3) << 14)
+#define IGC_SRRCTL_TIMER0SEL(timer)    (((timer) & 0x3) << 17)
+
+/* Sample RX tstamp in PHY sop */
+#define IGC_TSYNCRXCTL_RXSYNSIG         0x00000400
+
+/* Sample TX tstamp in PHY sop */
+#define IGC_TSYNCTXCTL_TXSYNSIG         0x00000020
+
 /* TSAUXC Configuration Bits */
 #define TSAUXC_EN_TT0	(1 << 0)  /* Enable target time 0. */
 #define TSAUXC_EN_TT1	(1 << 1)  /* Enable target time 1. */
Signature · 1 line
2.9.5
author
#9 lore raw

PATCH v2 3/3 net/igc: support IEEE 1588 PTP

In reply to Simei Su

Add igc support for new ethdev APIs to enable/disable and read/write/adjust IEEE1588 PTP timestamps.

The example command for running ptpclient is as below:
./build/examples/dpdk-ptpclient -c 1 -n 3 -- -T 0 -p 0x1

---
 doc/guides/nics/features/igc.ini       |   1 +
 doc/guides/rel_notes/release_23_03.rst |   3 +
 drivers/net/igc/igc_ethdev.c           | 222 +++++++++++++++++++++++++++++++++
 drivers/net/igc/igc_ethdev.h           |   4 +-
 drivers/net/igc/igc_txrx.c             |  50 +++++++-
 drivers/net/igc/igc_txrx.h             |   1 +
 6 files changed, 276 insertions(+), 5 deletions(-)
doc/guides/nics/features/igc.ini +1 -0
index b5deea3..25a997c 100644
@@ -33,6 +33,7 @@ VLAN filter          = Y
 VLAN offload         = Y
 Linux                = Y
 x86-64               = Y
+Timesync             = Y
 
 [rte_flow items]
 eth                  = P
doc/guides/rel_notes/release_23_03.rst +3 -0
index b8c5b68..6e086a2 100644
@@ -55,6 +55,9 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Updated Intel igc driver.**
+
+  * Added timesync API support.
 
 Removed Items
 -------------
drivers/net/igc/igc_ethdev.c +222 -0

246 lines not on this page · raw message

drivers/net/igc/igc_ethdev.h +3 -1
index f56cad7..237d3c1 100644
@@ -7,6 +7,7 @@
 
 #include <rte_ethdev.h>
 #include <rte_flow.h>
+#include <rte_time.h>
 
 #include "base/igc_osdep.h"
 #include "base/igc_hw.h"
@@ -75,7 +76,8 @@ extern "C" {
 	RTE_ETH_RX_OFFLOAD_SCTP_CKSUM  | \
 	RTE_ETH_RX_OFFLOAD_KEEP_CRC    | \
 	RTE_ETH_RX_OFFLOAD_SCATTER     | \
-	RTE_ETH_RX_OFFLOAD_RSS_HASH)
+	RTE_ETH_RX_OFFLOAD_RSS_HASH    | \
+	RTE_ETH_RX_OFFLOAD_TIMESTAMP)
 
 #define IGC_TX_OFFLOAD_ALL	(    \
 	RTE_ETH_TX_OFFLOAD_VLAN_INSERT | \
drivers/net/igc/igc_txrx.c +46 -4

106 lines not on this page · raw message

drivers/net/igc/igc_txrx.h +1 -0
index 5731761..e7272f8 100644
@@ -42,6 +42,7 @@ struct igc_rx_queue {
 	uint8_t             drop_en;    /**< If not 0, set SRRCTL.Drop_En. */
 	uint32_t            flags;      /**< RX flags. */
 	uint64_t            offloads;   /**< offloads of RTE_ETH_RX_OFFLOAD_* */
+	uint64_t            rx_timestamp;
 };
 
 /** Offload features */
Signature · 1 line
2.9.5
Acked-by on the v2 series Applied
#10 lore raw
In reply to Simei Su
Quoted 35 lines

-----Original Message-----
From: Su, Simei <[email protected]>
Sent: Tuesday, January 17, 2023 9:26 PM
To: Zhang, Qi Z <[email protected]>; Guo, Junfeng <[email protected]>
Cc: [email protected]; Wu, Wenjun1 <[email protected]>; Su, Simei <[email protected]>
Subject: [PATCH v2 0/3] net/igc: support PTP timesync

[PATCH v2 1/3] code refactoring.
[PATCH v2 2/3] add related definitions for ptp timesync. [PATCH v2 3/3] add IEEE1588 API to support timesync.

v2:
* Refine commit log.
* Update the doc/guides/nics/features/igc.ini to add "Timesync" feature.
* Add release notes.

Simei Su (3):
net/igc: code refactoring
net/igc/base: support PTP timesync
net/igc: support IEEE 1588 PTP

 doc/guides/nics/features/igc.ini       |   1 +
 doc/guides/rel_notes/release_23_03.rst |   3 +
 drivers/net/igc/base/igc_defines.h     |  11 ++
 drivers/net/igc/igc_ethdev.c           | 222
+++++++++++++++++++++++++++++++++
 drivers/net/igc/igc_ethdev.h           |   4 +-
 drivers/net/igc/igc_txrx.c             | 166 +++++++-----------------
 drivers/net/igc/igc_txrx.h             | 116 +++++++++++++++++
 7 files changed, 401 insertions(+), 122 deletions(-)
Quoted 2 lines

--
2.9.5

Refined PATCH 2/3 's title and commit log as below

net/igc/base: expose timesync registers

Add definitions for timesync related registers.

Applied to dpdk-next-net-intel.

Thanks
Qi