All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v7 0/3] net/i40e: configurable PTYPE mapping
@ 2017-04-04  1:55 Qi Zhang
  2017-04-04  1:55 ` [PATCH v7 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
                   ` (4 more replies)
  0 siblings, 5 replies; 21+ messages in thread
From: Qi Zhang @ 2017-04-04  1:55 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: jingjing.wu, helin.zhang, dev, Qi Zhang

The patch set create new APIs that help to change the mapping from hardware
defined packet type to software defined packet type for i40e NICs.
Keep these APIs private is because currently they are only meaningful for
devices that support dynamic PTYPE configuration, which may not be a general
device feature.

v7:

- Add Altivec vPMD support.

v6:

- Update testpmd_func.rst.

v5:

- Rebase to dpdk-next-net.

v4:

- Add comment to explain the "user defined" ptype.

v3:

- Fix compile error when CONFIG_RTE_LIBRTE_I40E_PMD=y in testpmd

v2:

- Add testpmd command line:
  ptype mapping get <port_id> <valid_only>
  ptype mapping replace <port_id> <target> <mask> <pkt_type>
  ptype mapping reset <port_id>
  ptype mapping update <port_id> <hw_ptype> <sw_ptype>

- Rename APIs to rte_pmd_i40e_ptype_mapping_xxx

- Add missing API declaration in rte_pmd_i40e_version.map

- Add missing ptype in check_invalid_pkt_type

- Fix couple typo error

Qi Zhang (3):
  net/i40e: enable per dev PTYPE mapping table
  net/i40e: configurable PTYPE mapping
  app/testpmd: add CL for ptype mapping configure

 app/test-pmd/cmdline.c                      | 372 ++++++++++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  36 +++
 drivers/net/i40e/i40e_ethdev.c              | 230 +++++++++++++++++
 drivers/net/i40e/i40e_ethdev.h              |   5 +
 drivers/net/i40e/i40e_ethdev_vf.c           |   2 +-
 drivers/net/i40e/i40e_rxtx.c                |  30 ++-
 drivers/net/i40e/i40e_rxtx.h                |   3 +-
 drivers/net/i40e/i40e_rxtx_vec_altivec.c    |  18 +-
 drivers/net/i40e/i40e_rxtx_vec_neon.c       |   8 +-
 drivers/net/i40e/i40e_rxtx_vec_sse.c        |  14 +-
 drivers/net/i40e/rte_pmd_i40e.h             |  86 +++++++
 drivers/net/i40e/rte_pmd_i40e_version.map   |   4 +
 12 files changed, 779 insertions(+), 29 deletions(-)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v7 1/3] net/i40e: enable per dev PTYPE mapping table
  2017-04-04  1:55 [PATCH v7 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
@ 2017-04-04  1:55 ` Qi Zhang
  2017-04-04  1:55 ` [PATCH v7 2/3] net/i40e: configurable PTYPE mapping Qi Zhang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: Qi Zhang @ 2017-04-04  1:55 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: jingjing.wu, helin.zhang, dev, Qi Zhang

The mapping from hardware defined packet type to software defined
packet type is static for i40e device, the patch let each ethdev to
to have their own copy of mapping table, this give the possibility
that different ethdev can be set different PTYPE mapping rule which
is the requirement to support following hardware's dynamic PTYPE
feature.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---

v7:

- Add Altivec vPMD support.
 
v5:

- Rebase to dpdk-next-net

 drivers/net/i40e/i40e_ethdev.c           |  1 +
 drivers/net/i40e/i40e_ethdev.h           |  5 +++++
 drivers/net/i40e/i40e_ethdev_vf.c        |  2 +-
 drivers/net/i40e/i40e_rxtx.c             | 30 ++++++++++++++++++++++--------
 drivers/net/i40e/i40e_rxtx.h             |  3 ++-
 drivers/net/i40e/i40e_rxtx_vec_altivec.c | 18 ++++++++----------
 drivers/net/i40e/i40e_rxtx_vec_neon.c    |  8 +++++---
 drivers/net/i40e/i40e_rxtx_vec_sse.c     | 14 ++++++++------
 8 files changed, 52 insertions(+), 29 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 00079bb..d7b9f8b 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -1058,6 +1058,7 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
 		i40e_set_tx_function(dev);
 		return 0;
 	}
+	i40e_set_default_ptype_table(dev);
 	pci_dev = I40E_DEV_TO_PCI(dev);
 	intr_handle = &pci_dev->intr_handle;
 
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index a8ecea4..38fcd94 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -740,6 +740,8 @@ struct i40e_vf {
 	uint64_t flags;
 };
 
+#define I40E_MAX_PKT_TYPE 256
+
 /*
  * Structure to store private data for each PF/VF instance.
  */
@@ -764,6 +766,9 @@ struct i40e_adapter {
 	struct rte_timecounter systime_tc;
 	struct rte_timecounter rx_tstamp_tc;
 	struct rte_timecounter tx_tstamp_tc;
+
+	/* ptype mapping table */
+	uint32_t ptype_tbl[I40E_MAX_PKT_TYPE] __rte_cache_min_aligned;
 };
 
 extern const struct rte_flow_ops i40e_flow_ops;
diff --git a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c
index d3659c9..da74824 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -1478,7 +1478,7 @@ i40evf_dev_init(struct rte_eth_dev *eth_dev)
 		i40e_set_tx_function(eth_dev);
 		return 0;
 	}
-
+	i40e_set_default_ptype_table(eth_dev);
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
 
diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c
index ff70c06..e5471b1 100644
--- a/drivers/net/i40e/i40e_rxtx.c
+++ b/drivers/net/i40e/i40e_rxtx.c
@@ -61,7 +61,6 @@
 
 #define DEFAULT_TX_RS_THRESH   32
 #define DEFAULT_TX_FREE_THRESH 32
-#define I40E_MAX_PKT_TYPE      256
 
 #define I40E_TX_MAX_BURST  32
 
@@ -458,6 +457,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 	int32_t s[I40E_LOOK_AHEAD], nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	rxdp = &rxq->rx_ring[rxq->rx_tail];
 	rxep = &rxq->sw_ring[rxq->rx_tail];
@@ -506,9 +506,9 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 			pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
 			pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
 			mb->packet_type =
-				i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
-						I40E_RXD_QW1_PTYPE_MASK) >>
-						I40E_RXD_QW1_PTYPE_SHIFT));
+				ptype_tbl[(uint8_t)((qword1 &
+				I40E_RXD_QW1_PTYPE_MASK) >>
+				I40E_RXD_QW1_PTYPE_SHIFT)];
 			if (pkt_flags & PKT_RX_RSS_HASH)
 				mb->hash.rss = rte_le_to_cpu_32(\
 					rxdp[j].wb.qword0.hi_dword.rss);
@@ -700,6 +700,7 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	uint16_t rx_id, nb_hold;
 	uint64_t dma_addr;
 	uint64_t pkt_flags;
+	uint32_t *ptype_tbl;
 
 	nb_rx = 0;
 	nb_hold = 0;
@@ -707,6 +708,7 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	rx_id = rxq->rx_tail;
 	rx_ring = rxq->rx_ring;
 	sw_ring = rxq->sw_ring;
+	ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	while (nb_rx < nb_pkts) {
 		rxdp = &rx_ring[rx_id];
@@ -763,8 +765,8 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 		pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
 		pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
 		rxm->packet_type =
-			i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
-			I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT));
+			ptype_tbl[(uint8_t)((qword1 &
+			I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
 		if (pkt_flags & PKT_RX_RSS_HASH)
 			rxm->hash.rss =
 				rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
@@ -818,6 +820,7 @@ i40e_recv_scattered_pkts(void *rx_queue,
 	uint64_t qword1;
 	uint64_t dma_addr;
 	uint64_t pkt_flags;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	while (nb_rx < nb_pkts) {
 		rxdp = &rx_ring[rx_id];
@@ -925,8 +928,8 @@ i40e_recv_scattered_pkts(void *rx_queue,
 		pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
 		pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
 		first_seg->packet_type =
-			i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
-			I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT));
+			ptype_tbl[(uint8_t)((qword1 &
+			I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
 		if (pkt_flags & PKT_RX_RSS_HASH)
 			first_seg->hash.rss =
 				rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
@@ -2922,6 +2925,17 @@ i40e_set_tx_function(struct rte_eth_dev *dev)
 	}
 }
 
+void __attribute__((cold))
+i40e_set_default_ptype_table(struct rte_eth_dev *dev)
+{
+	struct i40e_adapter *ad =
+		I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+	int i;
+
+	for (i = 0; i <= I40E_MAX_PKT_TYPE; i++)
+		ad->ptype_tbl[i] = i40e_get_default_pkt_type(i);
+}
+
 /* Stubs needed for linkage when CONFIG_RTE_I40E_INC_VECTOR is set to 'n' */
 int __attribute__((weak))
 i40e_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused *dev)
diff --git a/drivers/net/i40e/i40e_rxtx.h b/drivers/net/i40e/i40e_rxtx.h
index 2fa7f37..20084d6 100644
--- a/drivers/net/i40e/i40e_rxtx.h
+++ b/drivers/net/i40e/i40e_rxtx.h
@@ -254,13 +254,14 @@ void i40e_set_rx_function(struct rte_eth_dev *dev);
 void i40e_set_tx_function_flag(struct rte_eth_dev *dev,
 			       struct i40e_tx_queue *txq);
 void i40e_set_tx_function(struct rte_eth_dev *dev);
+void i40e_set_default_ptype_table(struct rte_eth_dev *dev);
 
 /* For each value it means, datasheet of hardware can tell more details
  *
  * @note: fix i40e_dev_supported_ptypes_get() if any change here.
  */
 static inline uint32_t
-i40e_rxd_pkt_type_mapping(uint8_t ptype)
+i40e_get_default_pkt_type(uint8_t ptype)
 {
 	static const uint32_t type_table[UINT8_MAX + 1] __rte_cache_aligned = {
 		/* L2 types */
diff --git a/drivers/net/i40e/i40e_rxtx_vec_altivec.c b/drivers/net/i40e/i40e_rxtx_vec_altivec.c
index 2f6f70a..5f525ff 100644
--- a/drivers/net/i40e/i40e_rxtx_vec_altivec.c
+++ b/drivers/net/i40e/i40e_rxtx_vec_altivec.c
@@ -209,7 +209,8 @@ desc_to_olflags_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts)
 #define PKTLEN_SHIFT     10
 
 static inline void
-desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts)
+desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts,
+		uint32_t *ptype_tbl)
 {
 	vector unsigned long ptype0 = vec_mergel(descs[0], descs[1]);
 	vector unsigned long ptype1 = vec_mergel(descs[2], descs[3]);
@@ -217,14 +218,10 @@ desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts)
 	ptype0 = vec_sr(ptype0, (vector unsigned long){30, 30});
 	ptype1 = vec_sr(ptype1, (vector unsigned long){30, 30});
 
-	rx_pkts[0]->packet_type = i40e_rxd_pkt_type_mapping(
-					(*(vector unsigned char *)&ptype0)[0]);
-	rx_pkts[1]->packet_type = i40e_rxd_pkt_type_mapping(
-					(*(vector unsigned char *)&ptype0)[8]);
-	rx_pkts[2]->packet_type = i40e_rxd_pkt_type_mapping(
-					(*(vector unsigned char *)&ptype1)[0]);
-	rx_pkts[3]->packet_type = i40e_rxd_pkt_type_mapping(
-					(*(vector unsigned char *)&ptype1)[8]);
+	rx_pkts[0]->packet_type = ptype_tbl[(*(vector unsigned char *)&ptype0)[0])];
+	rx_pkts[1]->packet_type = ptype_tbl[(*(vector unsigned char *)&ptype0)[8])];
+	rx_pkts[2]->packet_type = ptype_tbl[(*(vector unsigned char *)&ptype1)[0])];
+	rx_pkts[3]->packet_type = ptype_tbl[(*(vector unsigned char *)&ptype1)[8])];
 }
 
  /* Notice:
@@ -242,6 +239,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 	int pos;
 	uint64_t var;
 	vector unsigned char shuf_msk;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	vector unsigned short crc_adjust = (vector unsigned short){
 		0, 0,         /* ignore pkt_type field */
@@ -466,7 +464,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 		vec_st(pkt_mb1, 0,
 		 (vector unsigned char *)&rx_pkts[pos]->rx_descriptor_fields1
 		);
-		desc_to_ptype_v(descs, &rx_pkts[pos]);
+		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
 		desc_to_olflags_v(descs, &rx_pkts[pos]);
 
 		/* C.4 calc avaialbe number of desc */
diff --git a/drivers/net/i40e/i40e_rxtx_vec_neon.c b/drivers/net/i40e/i40e_rxtx_vec_neon.c
index bd7239b..00be542 100644
--- a/drivers/net/i40e/i40e_rxtx_vec_neon.c
+++ b/drivers/net/i40e/i40e_rxtx_vec_neon.c
@@ -196,7 +196,8 @@ desc_to_olflags_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts)
 #define I40E_VPMD_DESC_DD_MASK	0x0001000100010001ULL
 
 static inline void
-desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts)
+desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts,
+		uint32_t *ptype_tbl)
 {
 	int i;
 	uint8_t ptype;
@@ -205,7 +206,7 @@ desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts)
 	for (i = 0; i < 4; i++) {
 		tmp = vreinterpretq_u8_u64(vshrq_n_u64(descs[i], 30));
 		ptype = vgetq_lane_u8(tmp, 8);
-		rx_pkts[i]->packet_type = i40e_rxd_pkt_type_mapping(ptype);
+		rx_pkts[i]->packet_type = ptype_tbl[ptype];
 	}
 
 }
@@ -225,6 +226,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 	uint16_t nb_pkts_recd;
 	int pos;
 	uint64_t var;
+	uint32 *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	/* mask to shuffle from desc. to mbuf */
 	uint8x16_t shuf_msk = {
@@ -429,7 +431,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 			 pkt_mb2);
 		vst1q_u8((void *)&rx_pkts[pos]->rx_descriptor_fields1,
 			 pkt_mb1);
-		desc_to_ptype_v(descs, &rx_pkts[pos]);
+		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
 		/* C.4 calc avaialbe number of desc */
 		var = __builtin_popcountll(stat & I40E_VPMD_DESC_DD_MASK);
 		nb_pkts_recd += var;
diff --git a/drivers/net/i40e/i40e_rxtx_vec_sse.c b/drivers/net/i40e/i40e_rxtx_vec_sse.c
index deed7e2..c5d7083 100644
--- a/drivers/net/i40e/i40e_rxtx_vec_sse.c
+++ b/drivers/net/i40e/i40e_rxtx_vec_sse.c
@@ -218,7 +218,8 @@ desc_to_olflags_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
 #define PKTLEN_SHIFT     10
 
 static inline void
-desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
+desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts,
+		uint32_t *ptype_tbl)
 {
 	__m128i ptype0 = _mm_unpackhi_epi64(descs[0], descs[1]);
 	__m128i ptype1 = _mm_unpackhi_epi64(descs[2], descs[3]);
@@ -226,10 +227,10 @@ desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
 	ptype0 = _mm_srli_epi64(ptype0, 30);
 	ptype1 = _mm_srli_epi64(ptype1, 30);
 
-	rx_pkts[0]->packet_type = i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype0, 0));
-	rx_pkts[1]->packet_type = i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype0, 8));
-	rx_pkts[2]->packet_type = i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype1, 0));
-	rx_pkts[3]->packet_type = i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype1, 8));
+	rx_pkts[0]->packet_type = ptype_tbl[_mm_extract_epi8(ptype0, 0)];
+	rx_pkts[1]->packet_type = ptype_tbl[_mm_extract_epi8(ptype0, 8)];
+	rx_pkts[2]->packet_type = ptype_tbl[_mm_extract_epi8(ptype1, 0)];
+	rx_pkts[3]->packet_type = ptype_tbl[_mm_extract_epi8(ptype1, 8)];
 }
 
  /*
@@ -248,6 +249,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 	int pos;
 	uint64_t var;
 	__m128i shuf_msk;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	__m128i crc_adjust = _mm_set_epi16(
 				0, 0, 0,    /* ignore non-length fields */
@@ -441,7 +443,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 				 pkt_mb2);
 		_mm_storeu_si128((void *)&rx_pkts[pos]->rx_descriptor_fields1,
 				 pkt_mb1);
-		desc_to_ptype_v(descs, &rx_pkts[pos]);
+		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
 		/* C.4 calc avaialbe number of desc */
 		var = __builtin_popcountll(_mm_cvtsi128_si64(staterr));
 		nb_pkts_recd += var;
-- 
2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v7 2/3] net/i40e: configurable PTYPE mapping
  2017-04-04  1:55 [PATCH v7 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
  2017-04-04  1:55 ` [PATCH v7 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
@ 2017-04-04  1:55 ` Qi Zhang
  2017-04-04  1:55 ` [PATCH v7 3/3] app/testpmd: add CL for ptype mapping configure Qi Zhang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 21+ messages in thread
From: Qi Zhang @ 2017-04-04  1:55 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: jingjing.wu, helin.zhang, dev, Qi Zhang

The patch adds 4 APIs to support configurable
PTYPE mapping for i40e device.
rte_pmd_i40e_ptype_mapping_get.
rte_pmd_i40e_ptype_mapping_replace.
rte_pmd_i40e_ptype_mapping_reset.
rte_pmd_i40e_ptype_mapping_update.
The mapping from hardware defined packet type to software defined packet
type can be updated/reset/read out with these APIs.
Also a software ptype with the most significent bit set will be regarded
as a user defined ptype (RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK) so
application can use it to defined its own PTYPE naming system.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---

v5:

- Rebase to dpdk-next-net

v4:

- Add comment to explain the "user defined" ptype.

v2:

- Rename APIs to rte_pmd_i40e_ptype_mapping_xxx

- Add missing API declaration in rte_pmd_i40e_version.map

- Add missing PTYPE in check_invalid_pkt_type

- Fix couple typo error

 drivers/net/i40e/i40e_ethdev.c            | 229 ++++++++++++++++++++++++++++++
 drivers/net/i40e/rte_pmd_i40e.h           |  86 +++++++++++
 drivers/net/i40e/rte_pmd_i40e_version.map |   4 +
 3 files changed, 319 insertions(+)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index d7b9f8b..f900e19 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -12274,3 +12274,232 @@ rte_pmd_i40e_get_ddp_list(uint8_t port, uint8_t *buff, uint32_t size)
 
 	return status;
 }
+
+static int check_invalid_pkt_type(uint32_t pkt_type)
+{
+	uint32_t l2, l3, l4, tnl, il2, il3, il4;
+
+	l2 = pkt_type & RTE_PTYPE_L2_MASK;
+	l3 = pkt_type & RTE_PTYPE_L3_MASK;
+	l4 = pkt_type & RTE_PTYPE_L4_MASK;
+	tnl = pkt_type & RTE_PTYPE_TUNNEL_MASK;
+	il2 = pkt_type & RTE_PTYPE_INNER_L2_MASK;
+	il3 = pkt_type & RTE_PTYPE_INNER_L3_MASK;
+	il4 = pkt_type & RTE_PTYPE_INNER_L4_MASK;
+
+	if (l2 &&
+	    l2 != RTE_PTYPE_L2_ETHER &&
+	    l2 != RTE_PTYPE_L2_ETHER_TIMESYNC &&
+	    l2 != RTE_PTYPE_L2_ETHER_ARP &&
+	    l2 != RTE_PTYPE_L2_ETHER_LLDP &&
+	    l2 != RTE_PTYPE_L2_ETHER_NSH &&
+	    l2 != RTE_PTYPE_L2_ETHER_VLAN &&
+	    l2 != RTE_PTYPE_L2_ETHER_QINQ)
+		return -1;
+
+	if (l3 &&
+	    l3 != RTE_PTYPE_L3_IPV4 &&
+	    l3 != RTE_PTYPE_L3_IPV4_EXT &&
+	    l3 != RTE_PTYPE_L3_IPV6 &&
+	    l3 != RTE_PTYPE_L3_IPV4_EXT_UNKNOWN &&
+	    l3 != RTE_PTYPE_L3_IPV6_EXT &&
+	    l3 != RTE_PTYPE_L3_IPV6_EXT_UNKNOWN)
+		return -1;
+
+	if (l4 &&
+	    l4 != RTE_PTYPE_L4_TCP &&
+	    l4 != RTE_PTYPE_L4_UDP &&
+	    l4 != RTE_PTYPE_L4_FRAG &&
+	    l4 != RTE_PTYPE_L4_SCTP &&
+	    l4 != RTE_PTYPE_L4_ICMP &&
+	    l4 != RTE_PTYPE_L4_NONFRAG)
+		return -1;
+
+	if (tnl &&
+	    tnl != RTE_PTYPE_TUNNEL_IP &&
+	    tnl != RTE_PTYPE_TUNNEL_GRENAT &&
+	    tnl != RTE_PTYPE_TUNNEL_VXLAN &&
+	    tnl != RTE_PTYPE_TUNNEL_NVGRE &&
+	    tnl != RTE_PTYPE_TUNNEL_GENEVE &&
+	    tnl != RTE_PTYPE_TUNNEL_GRENAT)
+		return -1;
+
+	if (il2 &&
+	    il2 != RTE_PTYPE_INNER_L2_ETHER &&
+	    il2 != RTE_PTYPE_INNER_L2_ETHER_VLAN &&
+	    il2 != RTE_PTYPE_INNER_L2_ETHER_QINQ)
+		return -1;
+
+	if (il3 &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV4 &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV4_EXT &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV6 &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV6_EXT &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN)
+		return -1;
+
+	if (il4 &&
+	    il4 != RTE_PTYPE_INNER_L4_TCP &&
+	    il4 != RTE_PTYPE_INNER_L4_UDP &&
+	    il4 != RTE_PTYPE_INNER_L4_FRAG &&
+	    il4 != RTE_PTYPE_INNER_L4_SCTP &&
+	    il4 != RTE_PTYPE_INNER_L4_ICMP &&
+	    il4 != RTE_PTYPE_INNER_L4_NONFRAG)
+		return -1;
+
+	return 0;
+}
+
+static int check_invalid_ptype_mapping(
+		struct rte_pmd_i40e_ptype_mapping *mapping_table,
+		uint16_t count)
+{
+	int i;
+
+	for (i = 0; i < count; i++) {
+		uint16_t ptype = mapping_table[i].hw_ptype;
+		uint32_t pkt_type = mapping_table[i].sw_ptype;
+
+		if (ptype >= I40E_MAX_PKT_TYPE)
+			return -1;
+
+		if (pkt_type == RTE_PTYPE_UNKNOWN)
+			continue;
+
+		if (pkt_type & RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK)
+			continue;
+
+		if (check_invalid_pkt_type(pkt_type))
+			return -1;
+	}
+
+	return 0;
+}
+
+int
+rte_pmd_i40e_ptype_mapping_update(
+			uint8_t port,
+			struct rte_pmd_i40e_ptype_mapping *mapping_items,
+			uint16_t count,
+			uint8_t exclusive)
+{
+	struct rte_eth_dev *dev;
+	struct i40e_adapter *ad;
+	int i;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	if (!is_device_supported(dev, &rte_i40e_pmd))
+		return -ENOTSUP;
+
+	if (count > I40E_MAX_PKT_TYPE)
+		return -EINVAL;
+
+	if (check_invalid_ptype_mapping(mapping_items, count))
+		return -EINVAL;
+
+	ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+	if (exclusive) {
+		for (i = 0; i < I40E_MAX_PKT_TYPE; i++)
+			ad->ptype_tbl[i] = RTE_PTYPE_UNKNOWN;
+	}
+
+	for (i = 0; i < count; i++)
+		ad->ptype_tbl[mapping_items[i].hw_ptype]
+			= mapping_items[i].sw_ptype;
+
+	return 0;
+}
+
+int rte_pmd_i40e_ptype_mapping_reset(uint8_t port)
+{
+	struct rte_eth_dev *dev;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	if (!is_device_supported(dev, &rte_i40e_pmd))
+		return -ENOTSUP;
+
+	i40e_set_default_ptype_table(dev);
+
+	return 0;
+}
+
+int rte_pmd_i40e_ptype_mapping_get(
+			uint8_t port,
+			struct rte_pmd_i40e_ptype_mapping *mapping_items,
+			uint16_t size,
+			uint16_t *count,
+			uint8_t valid_only)
+{
+	struct rte_eth_dev *dev;
+	struct i40e_adapter *ad;
+	int n = 0;
+	uint16_t i;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	if (!is_device_supported(dev, &rte_i40e_pmd))
+		return -ENOTSUP;
+
+	ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+	for (i = 0; i < I40E_MAX_PKT_TYPE; i++) {
+		if (n >= size)
+			break;
+		if (valid_only && ad->ptype_tbl[i] == RTE_PTYPE_UNKNOWN)
+			continue;
+		mapping_items[n].hw_ptype = i;
+		mapping_items[n].sw_ptype = ad->ptype_tbl[i];
+		n++;
+	}
+
+	*count = n;
+	return 0;
+}
+
+int rte_pmd_i40e_ptype_mapping_replace(uint8_t port,
+				       uint32_t target,
+				       uint8_t mask,
+				       uint32_t pkt_type)
+{
+	struct rte_eth_dev *dev;
+	struct i40e_adapter *ad;
+	uint16_t i;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	if (!is_device_supported(dev, &rte_i40e_pmd))
+		return -ENOTSUP;
+
+	if (!mask && check_invalid_pkt_type(target))
+		return -EINVAL;
+
+	if (check_invalid_pkt_type(pkt_type))
+		return -EINVAL;
+
+	ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+	for (i = 0; i < I40E_MAX_PKT_TYPE; i++) {
+		if (mask) {
+			if ((target | ad->ptype_tbl[i]) == target &&
+			    (target & ad->ptype_tbl[i]))
+				ad->ptype_tbl[i] = pkt_type;
+		} else {
+			if (ad->ptype_tbl[i] == target)
+				ad->ptype_tbl[i] = pkt_type;
+		}
+	}
+
+	return 0;
+}
diff --git a/drivers/net/i40e/rte_pmd_i40e.h b/drivers/net/i40e/rte_pmd_i40e.h
index 8e15630..f7b76f7 100644
--- a/drivers/net/i40e/rte_pmd_i40e.h
+++ b/drivers/net/i40e/rte_pmd_i40e.h
@@ -107,6 +107,18 @@ struct rte_pmd_i40e_profile_list {
 };
 
 /**
+ * ptype mapping table only accept RTE_PTYPE_XXX or "user defined" ptype.
+ * A ptype with MSB set will be regarded as a user defined ptype.
+ * Below macro help to create a user defined ptype.
+ */
+#define RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK 0x80000000
+
+struct rte_pmd_i40e_ptype_mapping {
+	uint16_t hw_ptype; /**< hardware defined packet type*/
+	uint32_t sw_ptype; /**< software defined packet type */
+};
+
+/**
  * Notify VF when PF link status changes.
  *
  * @param port
@@ -495,4 +507,78 @@ int rte_pmd_i40e_process_ddp_package(uint8_t port, uint8_t *buff,
  */
 int rte_pmd_i40e_get_ddp_list(uint8_t port, uint8_t *buff, uint32_t size);
 
+/**
+ * Update hardware defined ptype to software defined packet type
+ * mapping table.
+ *
+ * @param port
+ *    pointer to port identifier of the device.
+ * @param mapping_items
+ *    the base address of the mapping items array.
+ * @param count
+ *    number of mapping items.
+ * @param exclusive
+ *    the flag indicate different ptype mapping update method.
+ *    -(0) only overwrite referred PTYPE mapping,
+ *	keep other PTYPEs mapping unchanged.
+ *    -(!0) overwrite referred PTYPE mapping,
+ *	set other PTYPEs maps to PTYPE_UNKNOWN.
+ */
+int rte_pmd_i40e_ptype_mapping_update(
+			uint8_t port,
+			struct rte_pmd_i40e_ptype_mapping *mapping_items,
+			uint16_t count,
+			uint8_t exclusive);
+
+/**
+ * Reset hardware defined ptype to software defined ptype
+ * mapping table to default.
+ *
+ * @param port
+ *    pointer to port identifier of the device
+ */
+int rte_pmd_i40e_ptype_mapping_reset(uint8_t port);
+
+/**
+ * Get hardware defined ptype to software defined ptype
+ * mapping items.
+ *
+ * @param port
+ *    pointer to port identifier of the device.
+ * @param mapping_items
+ *    the base address of the array to store returned items.
+ * @param size
+ *    the size of the input array.
+ * @param count
+ *    the place to store the number of returned items.
+ * @param valid_only
+ *    -(0) return full mapping table.
+ *    -(!0) only return mapping items which packet_type != RTE_PTYPE_UNKNOWN.
+ */
+int rte_pmd_i40e_ptype_mapping_get(
+			uint8_t port,
+			struct rte_pmd_i40e_ptype_mapping *mapping_items,
+			uint16_t size,
+			uint16_t *count,
+			uint8_t valid_only);
+
+/**
+ * Replace a specific or a group of software defined ptypes
+ * with a new one
+ *
+ * @param port
+ *    pointer to port identifier of the device
+ * @param target
+ *    the packet type to be replaced
+ * @param mask
+ *    -(0) target represent a specific software defined ptype.
+ *    -(!0) target is a mask to represent a group of software defined ptypes.
+ * @param pkt_type
+ *    the new packet type to overwrite
+ */
+int rte_pmd_i40e_ptype_mapping_replace(uint8_t port,
+				       uint32_t target,
+				       uint8_t mask,
+				       uint32_t pkt_type);
+
 #endif /* _PMD_I40E_H_ */
diff --git a/drivers/net/i40e/rte_pmd_i40e_version.map b/drivers/net/i40e/rte_pmd_i40e_version.map
index dbb994e..3b0e805 100644
--- a/drivers/net/i40e/rte_pmd_i40e_version.map
+++ b/drivers/net/i40e/rte_pmd_i40e_version.map
@@ -8,6 +8,10 @@ DPDK_17.02 {
 
 	rte_pmd_i40e_get_vf_stats;
 	rte_pmd_i40e_ping_vfs;
+	rte_pmd_i40e_ptype_mapping_get;
+	rte_pmd_i40e_ptype_mapping_replace;
+	rte_pmd_i40e_ptype_mapping_reset;
+	rte_pmd_i40e_ptype_mapping_update;
 	rte_pmd_i40e_reset_vf_stats;
 	rte_pmd_i40e_set_tx_loopback;
 	rte_pmd_i40e_set_vf_broadcast;
-- 
2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v7 3/3] app/testpmd: add CL for ptype mapping configure
  2017-04-04  1:55 [PATCH v7 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
  2017-04-04  1:55 ` [PATCH v7 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
  2017-04-04  1:55 ` [PATCH v7 2/3] net/i40e: configurable PTYPE mapping Qi Zhang
@ 2017-04-04  1:55 ` Qi Zhang
  2017-04-04  9:30 ` [PATCH v7 0/3] net/i40e: configurable PTYPE mapping Ferruh Yigit
  2017-04-07  3:25 ` [PATCH v8 " Qi Zhang
  4 siblings, 0 replies; 21+ messages in thread
From: Qi Zhang @ 2017-04-04  1:55 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: jingjing.wu, helin.zhang, dev, Qi Zhang

Add below command line to configure ptype mapping.
ptype mapping get <port_id> <valid_only>.
ptype mapping replace <port_id> <target> <mask> <pkt_type>.
ptype mapping reset <port_id>.
ptype mapping update <port_id> <hw_ptype> <sw_ptype>.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---

v6:

- Update testpmd_func.rst.

v5:

- Rebase to dpdk-next-net

v3:

- Fix compile issue when CONFIG_RTE_LIBRTE_I40E_PMD=n

 app/test-pmd/cmdline.c                      | 372 ++++++++++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  36 +++
 2 files changed, 408 insertions(+)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index aac4efb..402807b 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -596,6 +596,18 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"add ddp (port_id) (profile_path)\n"
 			"    Load a profile package on a port\n\n"
 
+			"ptype mapping get (port_id) (valid_only)\n"
+			"    Get ptype mapping on a port\n\n"
+
+			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
+			"    Replace target with the pkt_type in ptype mapping\n\n"
+
+			"ptype mapping reset (port_id)\n"
+			"    Reset ptype mapping on a port\n\n"
+
+			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
+			"    Update a ptype mapping item on a port\n\n"
+
 			, list_pkt_forwarding_modes()
 		);
 	}
@@ -12902,6 +12914,362 @@ cmdline_parse_inst_t cmd_get_ddp_list = {
 		NULL,
 	},
 };
+
+/* ptype mapping get */
+
+/* Common result structure for ptype mapping get */
+struct cmd_ptype_mapping_get_result {
+	cmdline_fixed_string_t ptype;
+	cmdline_fixed_string_t mapping;
+	cmdline_fixed_string_t get;
+	uint8_t port_id;
+	uint8_t valid_only;
+};
+
+/* Common CLI fields for ptype mapping get */
+cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 ptype, "ptype");
+cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 mapping, "mapping");
+cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 get, "get");
+cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 port_id, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 valid_only, UINT8);
+
+static void
+cmd_ptype_mapping_get_parsed(
+	void *parsed_result,
+	__attribute__((unused)) struct cmdline *cl,
+	__attribute__((unused)) void *data)
+{
+	struct cmd_ptype_mapping_get_result *res = parsed_result;
+	int ret = -ENOTSUP;
+#ifdef RTE_LIBRTE_I40E_PMD
+	int max_ptype_num = 256;
+	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
+	uint16_t count;
+	int i;
+#endif
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
+					mapping,
+					max_ptype_num,
+					&count,
+					res->valid_only);
+#endif
+
+	switch (ret) {
+	case 0:
+		break;
+	case -ENODEV:
+		printf("invalid port_id %d\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		printf("function not implemented\n");
+		break;
+	default:
+		printf("programming error: (%s)\n", strerror(-ret));
+	}
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	if (!ret) {
+		for (i = 0; i < count; i++)
+			printf("%3d\t0x%08x\n",
+				mapping[i].hw_ptype, mapping[i].sw_ptype);
+	}
+#endif
+}
+
+cmdline_parse_inst_t cmd_ptype_mapping_get = {
+	.f = cmd_ptype_mapping_get_parsed,
+	.data = NULL,
+	.help_str = "ptype mapping get <port_id> <valid_only>",
+	.tokens = {
+		(void *)&cmd_ptype_mapping_get_ptype,
+		(void *)&cmd_ptype_mapping_get_mapping,
+		(void *)&cmd_ptype_mapping_get_get,
+		(void *)&cmd_ptype_mapping_get_port_id,
+		(void *)&cmd_ptype_mapping_get_valid_only,
+		NULL,
+	},
+};
+
+/* ptype mapping replace */
+
+/* Common result structure for ptype mapping replace */
+struct cmd_ptype_mapping_replace_result {
+	cmdline_fixed_string_t ptype;
+	cmdline_fixed_string_t mapping;
+	cmdline_fixed_string_t replace;
+	uint8_t port_id;
+	uint32_t target;
+	uint8_t mask;
+	uint32_t pkt_type;
+};
+
+/* Common CLI fields for ptype mapping replace */
+cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 ptype, "ptype");
+cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 mapping, "mapping");
+cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 replace, "replace");
+cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 port_id, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 target, UINT32);
+cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 mask, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 pkt_type, UINT32);
+
+static void
+cmd_ptype_mapping_replace_parsed(
+	void *parsed_result,
+	__attribute__((unused)) struct cmdline *cl,
+	__attribute__((unused)) void *data)
+{
+	struct cmd_ptype_mapping_replace_result *res = parsed_result;
+	int ret = -ENOTSUP;
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
+					res->target,
+					res->mask,
+					res->pkt_type);
+#endif
+
+	switch (ret) {
+	case 0:
+		break;
+	case -EINVAL:
+		printf("invalid ptype 0x%8x or 0x%8x\n",
+				res->target, res->pkt_type);
+		break;
+	case -ENODEV:
+		printf("invalid port_id %d\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		printf("function not implemented\n");
+		break;
+	default:
+		printf("programming error: (%s)\n", strerror(-ret));
+	}
+}
+
+cmdline_parse_inst_t cmd_ptype_mapping_replace = {
+	.f = cmd_ptype_mapping_replace_parsed,
+	.data = NULL,
+	.help_str =
+		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
+	.tokens = {
+		(void *)&cmd_ptype_mapping_replace_ptype,
+		(void *)&cmd_ptype_mapping_replace_mapping,
+		(void *)&cmd_ptype_mapping_replace_replace,
+		(void *)&cmd_ptype_mapping_replace_port_id,
+		(void *)&cmd_ptype_mapping_replace_target,
+		(void *)&cmd_ptype_mapping_replace_mask,
+		(void *)&cmd_ptype_mapping_replace_pkt_type,
+		NULL,
+	},
+};
+
+/* ptype mapping reset */
+
+/* Common result structure for ptype mapping reset */
+struct cmd_ptype_mapping_reset_result {
+	cmdline_fixed_string_t ptype;
+	cmdline_fixed_string_t mapping;
+	cmdline_fixed_string_t reset;
+	uint8_t port_id;
+};
+
+/* Common CLI fields for ptype mapping reset*/
+cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_reset_result,
+		 ptype, "ptype");
+cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_reset_result,
+		 mapping, "mapping");
+cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_reset_result,
+		 reset, "reset");
+cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_reset_result,
+		 port_id, UINT8);
+
+static void
+cmd_ptype_mapping_reset_parsed(
+	void *parsed_result,
+	__attribute__((unused)) struct cmdline *cl,
+	__attribute__((unused)) void *data)
+{
+	struct cmd_ptype_mapping_reset_result *res = parsed_result;
+	int ret = -ENOTSUP;
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
+#endif
+
+	switch (ret) {
+	case 0:
+		break;
+	case -ENODEV:
+		printf("invalid port_id %d\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		printf("function not implemented\n");
+		break;
+	default:
+		printf("programming error: (%s)\n", strerror(-ret));
+	}
+}
+
+cmdline_parse_inst_t cmd_ptype_mapping_reset = {
+	.f = cmd_ptype_mapping_reset_parsed,
+	.data = NULL,
+	.help_str = "ptype mapping reset <port_id>",
+	.tokens = {
+		(void *)&cmd_ptype_mapping_reset_ptype,
+		(void *)&cmd_ptype_mapping_reset_mapping,
+		(void *)&cmd_ptype_mapping_reset_reset,
+		(void *)&cmd_ptype_mapping_reset_port_id,
+		NULL,
+	},
+};
+
+/* ptype mapping update */
+
+/* Common result structure for ptype mapping update */
+struct cmd_ptype_mapping_update_result {
+	cmdline_fixed_string_t ptype;
+	cmdline_fixed_string_t mapping;
+	cmdline_fixed_string_t reset;
+	uint8_t port_id;
+	uint8_t hw_ptype;
+	uint32_t sw_ptype;
+};
+
+/* Common CLI fields for ptype mapping update*/
+cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 ptype, "ptype");
+cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 mapping, "mapping");
+cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 reset, "update");
+cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 port_id, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 hw_ptype, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 sw_ptype, UINT32);
+
+static void
+cmd_ptype_mapping_update_parsed(
+	void *parsed_result,
+	__attribute__((unused)) struct cmdline *cl,
+	__attribute__((unused)) void *data)
+{
+	struct cmd_ptype_mapping_update_result *res = parsed_result;
+	int ret = -ENOTSUP;
+#ifdef RTE_LIBRTE_I40E_PMD
+	struct rte_pmd_i40e_ptype_mapping mapping;
+#endif
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	mapping.hw_ptype = res->hw_ptype;
+	mapping.sw_ptype = res->sw_ptype;
+	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
+						&mapping,
+						1,
+						0);
+#endif
+
+	switch (ret) {
+	case 0:
+		break;
+	case -EINVAL:
+		printf("invalid ptype 0x%8x\n", res->sw_ptype);
+		break;
+	case -ENODEV:
+		printf("invalid port_id %d\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		printf("function not implemented\n");
+		break;
+	default:
+		printf("programming error: (%s)\n", strerror(-ret));
+	}
+}
+
+cmdline_parse_inst_t cmd_ptype_mapping_update = {
+	.f = cmd_ptype_mapping_update_parsed,
+	.data = NULL,
+	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
+	.tokens = {
+		(void *)&cmd_ptype_mapping_update_ptype,
+		(void *)&cmd_ptype_mapping_update_mapping,
+		(void *)&cmd_ptype_mapping_update_update,
+		(void *)&cmd_ptype_mapping_update_port_id,
+		(void *)&cmd_ptype_mapping_update_hw_ptype,
+		(void *)&cmd_ptype_mapping_update_sw_ptype,
+		NULL,
+	},
+};
 /* ******************************************************************************** */
 
 /* list of instructions */
@@ -13083,6 +13451,10 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_strict_link_prio,
 	(cmdline_parse_inst_t *)&cmd_add_ddp,
 	(cmdline_parse_inst_t *)&cmd_get_ddp_list,
+	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
+	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
+	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
+	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
 	NULL,
 };
 
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 62478d6..90c771f 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -1136,6 +1136,42 @@ Add an E-tag forwarding filter on a port::
 Delete an E-tag forwarding filter on a port::
    testpmd> E-tag set filter del e-tag-id (value) port (port_id)
 
+ptype mapping
+~~~~~~~~~~~~~
+
+List all items from the ptype mapping table::
+
+   testpmd> ptype mapping get (port_id) (valid_only)
+
+Where:
+
+* ``valid_only``: A flag indicates if only list valid items(=1) or all itemss(=0).
+
+Replace a specific or a group of software defined ptype with a new one::
+
+   testpmd> ptype mapping replace  (port_id) (target) (mask) (pkt_type)
+
+where:
+
+* ``target``: A specific software ptype or a mask to represent a group of software ptypes.
+
+* ``mask``: A flag indicate if "target" is a specific software ptype(=0) or a ptype mask(=1).
+
+* ``pkt_type``: The new software ptype to replace the old ones.
+
+Update hardware defined ptype to software defined packet type mapping table::
+
+   testpmd> ptype mapping update (port_id) (hw_ptype) (sw_ptype)
+
+where:
+
+* ``hw_ptype``: hardware ptype as the index of the ptype mapping table.
+
+* ``sw_ptype``: software ptype as the value of the ptype mapping table.
+
+Reset ptype mapping table::
+
+   testpmd> ptype mapping reset (port_id)
 
 Port Functions
 --------------
-- 
2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v7 0/3] net/i40e: configurable PTYPE mapping
  2017-04-04  1:55 [PATCH v7 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
                   ` (2 preceding siblings ...)
  2017-04-04  1:55 ` [PATCH v7 3/3] app/testpmd: add CL for ptype mapping configure Qi Zhang
@ 2017-04-04  9:30 ` Ferruh Yigit
  2017-04-04 20:22   ` Thomas Monjalon
  2017-04-07  3:25 ` [PATCH v8 " Qi Zhang
  4 siblings, 1 reply; 21+ messages in thread
From: Ferruh Yigit @ 2017-04-04  9:30 UTC (permalink / raw)
  To: Qi Zhang; +Cc: jingjing.wu, helin.zhang, dev

On 4/4/2017 2:55 AM, Qi Zhang wrote:
> The patch set create new APIs that help to change the mapping from hardware
> defined packet type to software defined packet type for i40e NICs.
> Keep these APIs private is because currently they are only meaningful for
> devices that support dynamic PTYPE configuration, which may not be a general
> device feature.
> 

<...>

> 
> - Add testpmd command line:
>   ptype mapping get <port_id> <valid_only>
>   ptype mapping replace <port_id> <target> <mask> <pkt_type>
>   ptype mapping reset <port_id>
>   ptype mapping update <port_id> <hw_ptype> <sw_ptype>
> 
> - Rename APIs to rte_pmd_i40e_ptype_mapping_xxx
> 
> - Add missing API declaration in rte_pmd_i40e_version.map
> 
> - Add missing ptype in check_invalid_pkt_type
> 
> - Fix couple typo error
> 
> Qi Zhang (3):
>   net/i40e: enable per dev PTYPE mapping table
>   net/i40e: configurable PTYPE mapping
>   app/testpmd: add CL for ptype mapping configure

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

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v7 0/3] net/i40e: configurable PTYPE mapping
  2017-04-04  9:30 ` [PATCH v7 0/3] net/i40e: configurable PTYPE mapping Ferruh Yigit
@ 2017-04-04 20:22   ` Thomas Monjalon
  2017-04-05  5:45     ` Jianbo Liu
  0 siblings, 1 reply; 21+ messages in thread
From: Thomas Monjalon @ 2017-04-04 20:22 UTC (permalink / raw)
  To: Qi Zhang
  Cc: dev, Ferruh Yigit, jingjing.wu, helin.zhang, Jerin Jacob,
	Jianbo Liu, Chao Zhu

2017-04-04 10:30, Ferruh Yigit:
> On 4/4/2017 2:55 AM, Qi Zhang wrote:
> > The patch set create new APIs that help to change the mapping from hardware
> > defined packet type to software defined packet type for i40e NICs.
> > Keep these APIs private is because currently they are only meaningful for
> > devices that support dynamic PTYPE configuration, which may not be a general
> > device feature.
[...]
> > Qi Zhang (3):
> >   net/i40e: enable per dev PTYPE mapping table
> >   net/i40e: configurable PTYPE mapping
> >   app/testpmd: add CL for ptype mapping configure
> 
> Series applied to dpdk-next-net/master, thanks.

It does not compile for ARM (not tested for POWER):
	drivers/net/i40e/i40e_rxtx_vec_neon.c: In function '_recv_raw_pkts_vec':
		229:2: error: unknown type name 'uint32'
		uint32 *ptype_tbl = rxq->vsi->adapter->ptype_tbl;

Given that
	- it changes NEON and Altivec code
	- it does not compile on ARM
	- there is no Ack from NEON or Altivec maintainers (they were not Cc'ed)
I really doubt it has been tested.
That's why it won't be in RC1.

If NEON and Altivec maintainers agree, we can give it a chance for RC2.

PS: please use --in-reply-to to let us check the discussion history.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v7 0/3] net/i40e: configurable PTYPE mapping
  2017-04-04 20:22   ` Thomas Monjalon
@ 2017-04-05  5:45     ` Jianbo Liu
  2017-04-05  6:01       ` Zhang, Qi Z
  0 siblings, 1 reply; 21+ messages in thread
From: Jianbo Liu @ 2017-04-05  5:45 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: Qi Zhang, dev, Ferruh Yigit, Wu, Jingjing, Zhang, Helin,
	Jerin Jacob, Chao Zhu

On 5 April 2017 at 04:22, Thomas Monjalon <thomas.monjalon@6wind.com> wrote:
> 2017-04-04 10:30, Ferruh Yigit:
>> On 4/4/2017 2:55 AM, Qi Zhang wrote:
>> > The patch set create new APIs that help to change the mapping from hardware
>> > defined packet type to software defined packet type for i40e NICs.
>> > Keep these APIs private is because currently they are only meaningful for
>> > devices that support dynamic PTYPE configuration, which may not be a general
>> > device feature.
> [...]
>> > Qi Zhang (3):
>> >   net/i40e: enable per dev PTYPE mapping table
>> >   net/i40e: configurable PTYPE mapping
>> >   app/testpmd: add CL for ptype mapping configure
>>
>> Series applied to dpdk-next-net/master, thanks.
>
> It does not compile for ARM (not tested for POWER):
>         drivers/net/i40e/i40e_rxtx_vec_neon.c: In function '_recv_raw_pkts_vec':
>                 229:2: error: unknown type name 'uint32'
>                 uint32 *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
>

It must be uint32_t.

> Given that
>         - it changes NEON and Altivec code
>         - it does not compile on ARM
>         - there is no Ack from NEON or Altivec maintainers (they were not Cc'ed)
> I really doubt it has been tested.
> That's why it won't be in RC1.
>
> If NEON and Altivec maintainers agree, we can give it a chance for RC2.
>

Other than the above error on ARM:
Acked-by: Jianbo Liu <jianbo.liu@linaro.org>

> PS: please use --in-reply-to to let us check the discussion history.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v7 0/3] net/i40e: configurable PTYPE mapping
  2017-04-05  5:45     ` Jianbo Liu
@ 2017-04-05  6:01       ` Zhang, Qi Z
  0 siblings, 0 replies; 21+ messages in thread
From: Zhang, Qi Z @ 2017-04-05  6:01 UTC (permalink / raw)
  To: Jianbo Liu, Thomas Monjalon
  Cc: dev, Yigit, Ferruh, Wu, Jingjing, Zhang, Helin, Jerin Jacob, Chao Zhu



> -----Original Message-----
> From: Jianbo Liu [mailto:jianbo.liu@linaro.org]
> Sent: Wednesday, April 5, 2017 1:46 PM
> To: Thomas Monjalon <thomas.monjalon@6wind.com>
> Cc: Zhang, Qi Z <qi.z.zhang@intel.com>; dev@dpdk.org; Yigit, Ferruh
> <ferruh.yigit@intel.com>; Wu, Jingjing <jingjing.wu@intel.com>; Zhang,
> Helin <helin.zhang@intel.com>; Jerin Jacob
> <jerin.jacob@caviumnetworks.com>; Chao Zhu
> <chaozhu@linux.vnet.ibm.com>
> Subject: Re: [dpdk-dev] [PATCH v7 0/3] net/i40e: configurable PTYPE
> mapping
> 
> On 5 April 2017 at 04:22, Thomas Monjalon <thomas.monjalon@6wind.com>
> wrote:
> > 2017-04-04 10:30, Ferruh Yigit:
> >> On 4/4/2017 2:55 AM, Qi Zhang wrote:
> >> > The patch set create new APIs that help to change the mapping from
> >> > hardware defined packet type to software defined packet type for i40e
> NICs.
> >> > Keep these APIs private is because currently they are only
> >> > meaningful for devices that support dynamic PTYPE configuration,
> >> > which may not be a general device feature.
> > [...]
> >> > Qi Zhang (3):
> >> >   net/i40e: enable per dev PTYPE mapping table
> >> >   net/i40e: configurable PTYPE mapping
> >> >   app/testpmd: add CL for ptype mapping configure
> >>
> >> Series applied to dpdk-next-net/master, thanks.
> >
> > It does not compile for ARM (not tested for POWER):
> >         drivers/net/i40e/i40e_rxtx_vec_neon.c: In function
> '_recv_raw_pkts_vec':
> >                 229:2: error: unknown type name 'uint32'
> >                 uint32 *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> >
> 
> It must be uint32_t.
> 
> > Given that
> >         - it changes NEON and Altivec code
> >         - it does not compile on ARM
> >         - there is no Ack from NEON or Altivec maintainers (they were
> > not Cc'ed) I really doubt it has been tested.
> > That's why it won't be in RC1.
> >
> > If NEON and Altivec maintainers agree, we can give it a chance for RC2.
> >
> 
> Other than the above error on ARM:
> Acked-by: Jianbo Liu <jianbo.liu@linaro.org>

Thanks Jianbo.
I will rebase to RC1 and send v8.
Sorry for the inconvenient.
> 
> > PS: please use --in-reply-to to let us check the discussion history.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v8 1/3] net/i40e: enable per dev PTYPE mapping table
  2017-04-07  3:25   ` [PATCH v8 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
@ 2017-04-07  2:36     ` Zhang, Qi Z
  2017-04-12  2:13       ` Zhang, Qi Z
  0 siblings, 1 reply; 21+ messages in thread
From: Zhang, Qi Z @ 2017-04-07  2:36 UTC (permalink / raw)
  To: chaozhu; +Cc: Yigit, Ferruh, jianbo.liu, dev, Wu, Jingjing, Zhang, Helin

Hi Chao:
	Would you help to check the PowerPC part. (i40e_rxtx_vec_altivec.c)
Thanks
Qi

> -----Original Message-----
> From: Zhang, Qi Z
> Sent: Friday, April 7, 2017 11:25 AM
> To: Wu, Jingjing <jingjing.wu@intel.com>; Zhang, Helin
> <helin.zhang@intel.com>
> Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; jianbo.liu@linaro.org;
> chaozhu@linux.vnet.ibm.com; dev@dpdk.org; Zhang, Qi Z
> <qi.z.zhang@intel.com>
> Subject: [PATCH v8 1/3] net/i40e: enable per dev PTYPE mapping table
> 
> The mapping from hardware defined packet type to software defined packet
> type is static for i40e device, the patch let each ethdev to to have their own
> copy of mapping table, this give the possibility that different ethdev can be
> set different PTYPE mapping rule which is the requirement to support
> following hardware's dynamic PTYPE feature.
> 
> Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
> ---
> 
> v8:
> 
> - Fix compile error for ARM vPMD.
> 
> v7:
> 
> - Add Altivec vPMD support.
> 
> v5:
> 
> - Rebase to dpdk-next-net
> 
>  drivers/net/i40e/i40e_ethdev.c           |  1 +
>  drivers/net/i40e/i40e_ethdev.h           |  5 +++++
>  drivers/net/i40e/i40e_ethdev_vf.c        |  2 +-
>  drivers/net/i40e/i40e_rxtx.c             | 30
> ++++++++++++++++++++++--------
>  drivers/net/i40e/i40e_rxtx.h             |  3 ++-
>  drivers/net/i40e/i40e_rxtx_vec_altivec.c | 18 ++++++++----------
>  drivers/net/i40e/i40e_rxtx_vec_neon.c    |  8 +++++---
>  drivers/net/i40e/i40e_rxtx_vec_sse.c     | 14 ++++++++------
>  8 files changed, 52 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
> index 6927fde..2b95996 100644
> --- a/drivers/net/i40e/i40e_ethdev.c
> +++ b/drivers/net/i40e/i40e_ethdev.c
> @@ -1065,6 +1065,7 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
>  		i40e_set_tx_function(dev);
>  		return 0;
>  	}
> +	i40e_set_default_ptype_table(dev);
>  	pci_dev = I40E_DEV_TO_PCI(dev);
>  	intr_handle = &pci_dev->intr_handle;
> 
> diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
> index 69c6684..a1535b0 100644
> --- a/drivers/net/i40e/i40e_ethdev.h
> +++ b/drivers/net/i40e/i40e_ethdev.h
> @@ -744,6 +744,8 @@ struct i40e_vf {
>  	uint64_t flags;
>  };
> 
> +#define I40E_MAX_PKT_TYPE 256
> +
>  /*
>   * Structure to store private data for each PF/VF instance.
>   */
> @@ -768,6 +770,9 @@ struct i40e_adapter {
>  	struct rte_timecounter systime_tc;
>  	struct rte_timecounter rx_tstamp_tc;
>  	struct rte_timecounter tx_tstamp_tc;
> +
> +	/* ptype mapping table */
> +	uint32_t ptype_tbl[I40E_MAX_PKT_TYPE] __rte_cache_min_aligned;
>  };
> 
>  extern const struct rte_flow_ops i40e_flow_ops; diff --git
> a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c
> index 7e48fea..3db5b6f 100644
> --- a/drivers/net/i40e/i40e_ethdev_vf.c
> +++ b/drivers/net/i40e/i40e_ethdev_vf.c
> @@ -1477,7 +1477,7 @@ i40evf_dev_init(struct rte_eth_dev *eth_dev)
>  		i40e_set_tx_function(eth_dev);
>  		return 0;
>  	}
> -
> +	i40e_set_default_ptype_table(eth_dev);
>  	rte_eth_copy_pci_info(eth_dev, pci_dev);
>  	eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
> 
> diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c index
> ff70c06..e5471b1 100644
> --- a/drivers/net/i40e/i40e_rxtx.c
> +++ b/drivers/net/i40e/i40e_rxtx.c
> @@ -61,7 +61,6 @@
> 
>  #define DEFAULT_TX_RS_THRESH   32
>  #define DEFAULT_TX_FREE_THRESH 32
> -#define I40E_MAX_PKT_TYPE      256
> 
>  #define I40E_TX_MAX_BURST  32
> 
> @@ -458,6 +457,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
>  	int32_t s[I40E_LOOK_AHEAD], nb_dd;
>  	int32_t i, j, nb_rx = 0;
>  	uint64_t pkt_flags;
> +	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> 
>  	rxdp = &rxq->rx_ring[rxq->rx_tail];
>  	rxep = &rxq->sw_ring[rxq->rx_tail];
> @@ -506,9 +506,9 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
>  			pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
>  			pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
>  			mb->packet_type =
> -				i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
> -						I40E_RXD_QW1_PTYPE_MASK) >>
> -						I40E_RXD_QW1_PTYPE_SHIFT));
> +				ptype_tbl[(uint8_t)((qword1 &
> +				I40E_RXD_QW1_PTYPE_MASK) >>
> +				I40E_RXD_QW1_PTYPE_SHIFT)];
>  			if (pkt_flags & PKT_RX_RSS_HASH)
>  				mb->hash.rss = rte_le_to_cpu_32(\
>  					rxdp[j].wb.qword0.hi_dword.rss);
> @@ -700,6 +700,7 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf
> **rx_pkts, uint16_t nb_pkts)
>  	uint16_t rx_id, nb_hold;
>  	uint64_t dma_addr;
>  	uint64_t pkt_flags;
> +	uint32_t *ptype_tbl;
> 
>  	nb_rx = 0;
>  	nb_hold = 0;
> @@ -707,6 +708,7 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf
> **rx_pkts, uint16_t nb_pkts)
>  	rx_id = rxq->rx_tail;
>  	rx_ring = rxq->rx_ring;
>  	sw_ring = rxq->sw_ring;
> +	ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> 
>  	while (nb_rx < nb_pkts) {
>  		rxdp = &rx_ring[rx_id];
> @@ -763,8 +765,8 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf
> **rx_pkts, uint16_t nb_pkts)
>  		pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
>  		pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
>  		rxm->packet_type =
> -			i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
> -			I40E_RXD_QW1_PTYPE_MASK) >>
> I40E_RXD_QW1_PTYPE_SHIFT));
> +			ptype_tbl[(uint8_t)((qword1 &
> +			I40E_RXD_QW1_PTYPE_MASK) >>
> I40E_RXD_QW1_PTYPE_SHIFT)];
>  		if (pkt_flags & PKT_RX_RSS_HASH)
>  			rxm->hash.rss =
>  				rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
> @@ -818,6 +820,7 @@ i40e_recv_scattered_pkts(void *rx_queue,
>  	uint64_t qword1;
>  	uint64_t dma_addr;
>  	uint64_t pkt_flags;
> +	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> 
>  	while (nb_rx < nb_pkts) {
>  		rxdp = &rx_ring[rx_id];
> @@ -925,8 +928,8 @@ i40e_recv_scattered_pkts(void *rx_queue,
>  		pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
>  		pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
>  		first_seg->packet_type =
> -			i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
> -			I40E_RXD_QW1_PTYPE_MASK) >>
> I40E_RXD_QW1_PTYPE_SHIFT));
> +			ptype_tbl[(uint8_t)((qword1 &
> +			I40E_RXD_QW1_PTYPE_MASK) >>
> I40E_RXD_QW1_PTYPE_SHIFT)];
>  		if (pkt_flags & PKT_RX_RSS_HASH)
>  			first_seg->hash.rss =
>  				rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
> @@ -2922,6 +2925,17 @@ i40e_set_tx_function(struct rte_eth_dev *dev)
>  	}
>  }
> 
> +void __attribute__((cold))
> +i40e_set_default_ptype_table(struct rte_eth_dev *dev) {
> +	struct i40e_adapter *ad =
> +		I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
> +	int i;
> +
> +	for (i = 0; i <= I40E_MAX_PKT_TYPE; i++)
> +		ad->ptype_tbl[i] = i40e_get_default_pkt_type(i); }
> +
>  /* Stubs needed for linkage when CONFIG_RTE_I40E_INC_VECTOR is set to
> 'n' */  int __attribute__((weak))
> i40e_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused
> *dev) diff --git a/drivers/net/i40e/i40e_rxtx.h b/drivers/net/i40e/i40e_rxtx.h
> index 2fa7f37..20084d6 100644
> --- a/drivers/net/i40e/i40e_rxtx.h
> +++ b/drivers/net/i40e/i40e_rxtx.h
> @@ -254,13 +254,14 @@ void i40e_set_rx_function(struct rte_eth_dev
> *dev);  void i40e_set_tx_function_flag(struct rte_eth_dev *dev,
>  			       struct i40e_tx_queue *txq);
>  void i40e_set_tx_function(struct rte_eth_dev *dev);
> +void i40e_set_default_ptype_table(struct rte_eth_dev *dev);
> 
>  /* For each value it means, datasheet of hardware can tell more details
>   *
>   * @note: fix i40e_dev_supported_ptypes_get() if any change here.
>   */
>  static inline uint32_t
> -i40e_rxd_pkt_type_mapping(uint8_t ptype)
> +i40e_get_default_pkt_type(uint8_t ptype)
>  {
>  	static const uint32_t type_table[UINT8_MAX + 1] __rte_cache_aligned
> = {
>  		/* L2 types */
> diff --git a/drivers/net/i40e/i40e_rxtx_vec_altivec.c
> b/drivers/net/i40e/i40e_rxtx_vec_altivec.c
> index 2f6f70a..5f525ff 100644
> --- a/drivers/net/i40e/i40e_rxtx_vec_altivec.c
> +++ b/drivers/net/i40e/i40e_rxtx_vec_altivec.c
> @@ -209,7 +209,8 @@ desc_to_olflags_v(vector unsigned long descs[4],
> struct rte_mbuf **rx_pkts)
>  #define PKTLEN_SHIFT     10
> 
>  static inline void
> -desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts)
> +desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts,
> +		uint32_t *ptype_tbl)
>  {
>  	vector unsigned long ptype0 = vec_mergel(descs[0], descs[1]);
>  	vector unsigned long ptype1 = vec_mergel(descs[2], descs[3]); @@
> -217,14 +218,10 @@ desc_to_ptype_v(vector unsigned long descs[4], struct
> rte_mbuf **rx_pkts)
>  	ptype0 = vec_sr(ptype0, (vector unsigned long){30, 30});
>  	ptype1 = vec_sr(ptype1, (vector unsigned long){30, 30});
> 
> -	rx_pkts[0]->packet_type = i40e_rxd_pkt_type_mapping(
> -					(*(vector unsigned char *)&ptype0)[0]);
> -	rx_pkts[1]->packet_type = i40e_rxd_pkt_type_mapping(
> -					(*(vector unsigned char *)&ptype0)[8]);
> -	rx_pkts[2]->packet_type = i40e_rxd_pkt_type_mapping(
> -					(*(vector unsigned char *)&ptype1)[0]);
> -	rx_pkts[3]->packet_type = i40e_rxd_pkt_type_mapping(
> -					(*(vector unsigned char *)&ptype1)[8]);
> +	rx_pkts[0]->packet_type = ptype_tbl[(*(vector unsigned char
> *)&ptype0)[0])];
> +	rx_pkts[1]->packet_type = ptype_tbl[(*(vector unsigned char
> *)&ptype0)[8])];
> +	rx_pkts[2]->packet_type = ptype_tbl[(*(vector unsigned char
> *)&ptype1)[0])];
> +	rx_pkts[3]->packet_type = ptype_tbl[(*(vector unsigned char
> +*)&ptype1)[8])];
>  }
> 
>   /* Notice:
> @@ -242,6 +239,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq,
> struct rte_mbuf **rx_pkts,
>  	int pos;
>  	uint64_t var;
>  	vector unsigned char shuf_msk;
> +	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> 
>  	vector unsigned short crc_adjust = (vector unsigned short){
>  		0, 0,         /* ignore pkt_type field */
> @@ -466,7 +464,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq,
> struct rte_mbuf **rx_pkts,
>  		vec_st(pkt_mb1, 0,
>  		 (vector unsigned char *)&rx_pkts[pos]->rx_descriptor_fields1
>  		);
> -		desc_to_ptype_v(descs, &rx_pkts[pos]);
> +		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
>  		desc_to_olflags_v(descs, &rx_pkts[pos]);
> 
>  		/* C.4 calc avaialbe number of desc */ diff --git
> a/drivers/net/i40e/i40e_rxtx_vec_neon.c
> b/drivers/net/i40e/i40e_rxtx_vec_neon.c
> index bd7239b..515931e 100644
> --- a/drivers/net/i40e/i40e_rxtx_vec_neon.c
> +++ b/drivers/net/i40e/i40e_rxtx_vec_neon.c
> @@ -196,7 +196,8 @@ desc_to_olflags_v(uint64x2_t descs[4], struct
> rte_mbuf **rx_pkts)
>  #define I40E_VPMD_DESC_DD_MASK	0x0001000100010001ULL
> 
>  static inline void
> -desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts)
> +desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts,
> +		uint32_t *ptype_tbl)
>  {
>  	int i;
>  	uint8_t ptype;
> @@ -205,7 +206,7 @@ desc_to_ptype_v(uint64x2_t descs[4], struct
> rte_mbuf **rx_pkts)
>  	for (i = 0; i < 4; i++) {
>  		tmp = vreinterpretq_u8_u64(vshrq_n_u64(descs[i], 30));
>  		ptype = vgetq_lane_u8(tmp, 8);
> -		rx_pkts[i]->packet_type = i40e_rxd_pkt_type_mapping(ptype);
> +		rx_pkts[i]->packet_type = ptype_tbl[ptype];
>  	}
> 
>  }
> @@ -225,6 +226,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq,
> struct rte_mbuf **rx_pkts,
>  	uint16_t nb_pkts_recd;
>  	int pos;
>  	uint64_t var;
> +	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> 
>  	/* mask to shuffle from desc. to mbuf */
>  	uint8x16_t shuf_msk = {
> @@ -429,7 +431,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq,
> struct rte_mbuf **rx_pkts,
>  			 pkt_mb2);
>  		vst1q_u8((void *)&rx_pkts[pos]->rx_descriptor_fields1,
>  			 pkt_mb1);
> -		desc_to_ptype_v(descs, &rx_pkts[pos]);
> +		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
>  		/* C.4 calc avaialbe number of desc */
>  		var = __builtin_popcountll(stat & I40E_VPMD_DESC_DD_MASK);
>  		nb_pkts_recd += var;
> diff --git a/drivers/net/i40e/i40e_rxtx_vec_sse.c
> b/drivers/net/i40e/i40e_rxtx_vec_sse.c
> index fdd4a34..335098a 100644
> --- a/drivers/net/i40e/i40e_rxtx_vec_sse.c
> +++ b/drivers/net/i40e/i40e_rxtx_vec_sse.c
> @@ -215,7 +215,8 @@ desc_to_olflags_v(__m128i descs[4], struct
> rte_mbuf **rx_pkts)
>  #define PKTLEN_SHIFT     10
> 
>  static inline void
> -desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
> +desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts,
> +		uint32_t *ptype_tbl)
>  {
>  	__m128i ptype0 = _mm_unpackhi_epi64(descs[0], descs[1]);
>  	__m128i ptype1 = _mm_unpackhi_epi64(descs[2], descs[3]); @@
> -223,10 +224,10 @@ desc_to_ptype_v(__m128i descs[4], struct rte_mbuf
> **rx_pkts)
>  	ptype0 = _mm_srli_epi64(ptype0, 30);
>  	ptype1 = _mm_srli_epi64(ptype1, 30);
> 
> -	rx_pkts[0]->packet_type =
> i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype0, 0));
> -	rx_pkts[1]->packet_type =
> i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype0, 8));
> -	rx_pkts[2]->packet_type =
> i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype1, 0));
> -	rx_pkts[3]->packet_type =
> i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype1, 8));
> +	rx_pkts[0]->packet_type = ptype_tbl[_mm_extract_epi8(ptype0, 0)];
> +	rx_pkts[1]->packet_type = ptype_tbl[_mm_extract_epi8(ptype0, 8)];
> +	rx_pkts[2]->packet_type = ptype_tbl[_mm_extract_epi8(ptype1, 0)];
> +	rx_pkts[3]->packet_type = ptype_tbl[_mm_extract_epi8(ptype1, 8)];
>  }
> 
>   /*
> @@ -245,6 +246,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq,
> struct rte_mbuf **rx_pkts,
>  	int pos;
>  	uint64_t var;
>  	__m128i shuf_msk;
> +	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> 
>  	__m128i crc_adjust = _mm_set_epi16(
>  				0, 0, 0,    /* ignore non-length fields */
> @@ -432,7 +434,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq,
> struct rte_mbuf **rx_pkts,
>  				 pkt_mb2);
>  		_mm_storeu_si128((void *)&rx_pkts[pos]->rx_descriptor_fields1,
>  				 pkt_mb1);
> -		desc_to_ptype_v(descs, &rx_pkts[pos]);
> +		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
>  		/* C.4 calc avaialbe number of desc */
>  		var = __builtin_popcountll(_mm_cvtsi128_si64(staterr));
>  		nb_pkts_recd += var;
> --
> 2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v8 0/3] net/i40e: configurable PTYPE mapping
  2017-04-04  1:55 [PATCH v7 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
                   ` (3 preceding siblings ...)
  2017-04-04  9:30 ` [PATCH v7 0/3] net/i40e: configurable PTYPE mapping Ferruh Yigit
@ 2017-04-07  3:25 ` Qi Zhang
  2017-04-07  3:25   ` [PATCH v8 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
                     ` (3 more replies)
  4 siblings, 4 replies; 21+ messages in thread
From: Qi Zhang @ 2017-04-07  3:25 UTC (permalink / raw)
  To: jingjing.wu, helin.zhang; +Cc: ferruh.yigit, jianbo.liu, chaozhu, dev, Qi Zhang

The patch set create new APIs that help to change the mapping from hardware
defined packet type to software defined packet type for i40e NICs.
Keep these APIs private is because currently they are only meaningful for
devices that support dynamic PTYPE configuration, which may not be a general
device feature.

v8:

- Fix compile error on for ARM vPMD
- Rebase to 17.05-rc1

v7:

- Add Altivec vPMD support.

v6:

- Update testpmd_func.rst.

v5:

- Rebase to dpdk-next-net.

v4:

- Add comment to explain the "user defined" ptype.

v3:

- Fix compile error when CONFIG_RTE_LIBRTE_I40E_PMD=y in testpmd

v2:

- Add testpmd command line:
  ptype mapping get <port_id> <valid_only>
  ptype mapping replace <port_id> <target> <mask> <pkt_type>
  ptype mapping reset <port_id>
  ptype mapping update <port_id> <hw_ptype> <sw_ptype>

- Rename APIs to rte_pmd_i40e_ptype_mapping_xxx

- Add missing API declaration in rte_pmd_i40e_version.map

- Add missing ptype in check_invalid_pkt_type

- Fix couple typo error

Qi Zhang (3):
  net/i40e: enable per dev PTYPE mapping table
  net/i40e: configurable PTYPE mapping
  app/testpmd: add CL for ptype mapping configure

 app/test-pmd/cmdline.c                      | 372 ++++++++++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  36 +++
 drivers/net/i40e/i40e_ethdev.c              | 230 +++++++++++++++++
 drivers/net/i40e/i40e_ethdev.h              |   5 +
 drivers/net/i40e/i40e_ethdev_vf.c           |   2 +-
 drivers/net/i40e/i40e_rxtx.c                |  30 ++-
 drivers/net/i40e/i40e_rxtx.h                |   3 +-
 drivers/net/i40e/i40e_rxtx_vec_altivec.c    |  18 +-
 drivers/net/i40e/i40e_rxtx_vec_neon.c       |   8 +-
 drivers/net/i40e/i40e_rxtx_vec_sse.c        |  14 +-
 drivers/net/i40e/rte_pmd_i40e.h             |  86 +++++++
 drivers/net/i40e/rte_pmd_i40e_version.map   |   4 +
 12 files changed, 779 insertions(+), 29 deletions(-)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v8 1/3] net/i40e: enable per dev PTYPE mapping table
  2017-04-07  3:25 ` [PATCH v8 " Qi Zhang
@ 2017-04-07  3:25   ` Qi Zhang
  2017-04-07  2:36     ` Zhang, Qi Z
  2017-04-07  3:25   ` [PATCH v8 2/3] net/i40e: configurable PTYPE mapping Qi Zhang
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 21+ messages in thread
From: Qi Zhang @ 2017-04-07  3:25 UTC (permalink / raw)
  To: jingjing.wu, helin.zhang; +Cc: ferruh.yigit, jianbo.liu, chaozhu, dev, Qi Zhang

The mapping from hardware defined packet type to software defined
packet type is static for i40e device, the patch let each ethdev to
to have their own copy of mapping table, this give the possibility
that different ethdev can be set different PTYPE mapping rule which
is the requirement to support following hardware's dynamic PTYPE
feature.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---

v8:

- Fix compile error for ARM vPMD.

v7:

- Add Altivec vPMD support.
 
v5:

- Rebase to dpdk-next-net

 drivers/net/i40e/i40e_ethdev.c           |  1 +
 drivers/net/i40e/i40e_ethdev.h           |  5 +++++
 drivers/net/i40e/i40e_ethdev_vf.c        |  2 +-
 drivers/net/i40e/i40e_rxtx.c             | 30 ++++++++++++++++++++++--------
 drivers/net/i40e/i40e_rxtx.h             |  3 ++-
 drivers/net/i40e/i40e_rxtx_vec_altivec.c | 18 ++++++++----------
 drivers/net/i40e/i40e_rxtx_vec_neon.c    |  8 +++++---
 drivers/net/i40e/i40e_rxtx_vec_sse.c     | 14 ++++++++------
 8 files changed, 52 insertions(+), 29 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 6927fde..2b95996 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -1065,6 +1065,7 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
 		i40e_set_tx_function(dev);
 		return 0;
 	}
+	i40e_set_default_ptype_table(dev);
 	pci_dev = I40E_DEV_TO_PCI(dev);
 	intr_handle = &pci_dev->intr_handle;
 
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index 69c6684..a1535b0 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -744,6 +744,8 @@ struct i40e_vf {
 	uint64_t flags;
 };
 
+#define I40E_MAX_PKT_TYPE 256
+
 /*
  * Structure to store private data for each PF/VF instance.
  */
@@ -768,6 +770,9 @@ struct i40e_adapter {
 	struct rte_timecounter systime_tc;
 	struct rte_timecounter rx_tstamp_tc;
 	struct rte_timecounter tx_tstamp_tc;
+
+	/* ptype mapping table */
+	uint32_t ptype_tbl[I40E_MAX_PKT_TYPE] __rte_cache_min_aligned;
 };
 
 extern const struct rte_flow_ops i40e_flow_ops;
diff --git a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c
index 7e48fea..3db5b6f 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -1477,7 +1477,7 @@ i40evf_dev_init(struct rte_eth_dev *eth_dev)
 		i40e_set_tx_function(eth_dev);
 		return 0;
 	}
-
+	i40e_set_default_ptype_table(eth_dev);
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
 
diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c
index ff70c06..e5471b1 100644
--- a/drivers/net/i40e/i40e_rxtx.c
+++ b/drivers/net/i40e/i40e_rxtx.c
@@ -61,7 +61,6 @@
 
 #define DEFAULT_TX_RS_THRESH   32
 #define DEFAULT_TX_FREE_THRESH 32
-#define I40E_MAX_PKT_TYPE      256
 
 #define I40E_TX_MAX_BURST  32
 
@@ -458,6 +457,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 	int32_t s[I40E_LOOK_AHEAD], nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	rxdp = &rxq->rx_ring[rxq->rx_tail];
 	rxep = &rxq->sw_ring[rxq->rx_tail];
@@ -506,9 +506,9 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 			pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
 			pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
 			mb->packet_type =
-				i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
-						I40E_RXD_QW1_PTYPE_MASK) >>
-						I40E_RXD_QW1_PTYPE_SHIFT));
+				ptype_tbl[(uint8_t)((qword1 &
+				I40E_RXD_QW1_PTYPE_MASK) >>
+				I40E_RXD_QW1_PTYPE_SHIFT)];
 			if (pkt_flags & PKT_RX_RSS_HASH)
 				mb->hash.rss = rte_le_to_cpu_32(\
 					rxdp[j].wb.qword0.hi_dword.rss);
@@ -700,6 +700,7 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	uint16_t rx_id, nb_hold;
 	uint64_t dma_addr;
 	uint64_t pkt_flags;
+	uint32_t *ptype_tbl;
 
 	nb_rx = 0;
 	nb_hold = 0;
@@ -707,6 +708,7 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	rx_id = rxq->rx_tail;
 	rx_ring = rxq->rx_ring;
 	sw_ring = rxq->sw_ring;
+	ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	while (nb_rx < nb_pkts) {
 		rxdp = &rx_ring[rx_id];
@@ -763,8 +765,8 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 		pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
 		pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
 		rxm->packet_type =
-			i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
-			I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT));
+			ptype_tbl[(uint8_t)((qword1 &
+			I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
 		if (pkt_flags & PKT_RX_RSS_HASH)
 			rxm->hash.rss =
 				rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
@@ -818,6 +820,7 @@ i40e_recv_scattered_pkts(void *rx_queue,
 	uint64_t qword1;
 	uint64_t dma_addr;
 	uint64_t pkt_flags;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	while (nb_rx < nb_pkts) {
 		rxdp = &rx_ring[rx_id];
@@ -925,8 +928,8 @@ i40e_recv_scattered_pkts(void *rx_queue,
 		pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
 		pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
 		first_seg->packet_type =
-			i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
-			I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT));
+			ptype_tbl[(uint8_t)((qword1 &
+			I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
 		if (pkt_flags & PKT_RX_RSS_HASH)
 			first_seg->hash.rss =
 				rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
@@ -2922,6 +2925,17 @@ i40e_set_tx_function(struct rte_eth_dev *dev)
 	}
 }
 
+void __attribute__((cold))
+i40e_set_default_ptype_table(struct rte_eth_dev *dev)
+{
+	struct i40e_adapter *ad =
+		I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+	int i;
+
+	for (i = 0; i <= I40E_MAX_PKT_TYPE; i++)
+		ad->ptype_tbl[i] = i40e_get_default_pkt_type(i);
+}
+
 /* Stubs needed for linkage when CONFIG_RTE_I40E_INC_VECTOR is set to 'n' */
 int __attribute__((weak))
 i40e_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused *dev)
diff --git a/drivers/net/i40e/i40e_rxtx.h b/drivers/net/i40e/i40e_rxtx.h
index 2fa7f37..20084d6 100644
--- a/drivers/net/i40e/i40e_rxtx.h
+++ b/drivers/net/i40e/i40e_rxtx.h
@@ -254,13 +254,14 @@ void i40e_set_rx_function(struct rte_eth_dev *dev);
 void i40e_set_tx_function_flag(struct rte_eth_dev *dev,
 			       struct i40e_tx_queue *txq);
 void i40e_set_tx_function(struct rte_eth_dev *dev);
+void i40e_set_default_ptype_table(struct rte_eth_dev *dev);
 
 /* For each value it means, datasheet of hardware can tell more details
  *
  * @note: fix i40e_dev_supported_ptypes_get() if any change here.
  */
 static inline uint32_t
-i40e_rxd_pkt_type_mapping(uint8_t ptype)
+i40e_get_default_pkt_type(uint8_t ptype)
 {
 	static const uint32_t type_table[UINT8_MAX + 1] __rte_cache_aligned = {
 		/* L2 types */
diff --git a/drivers/net/i40e/i40e_rxtx_vec_altivec.c b/drivers/net/i40e/i40e_rxtx_vec_altivec.c
index 2f6f70a..5f525ff 100644
--- a/drivers/net/i40e/i40e_rxtx_vec_altivec.c
+++ b/drivers/net/i40e/i40e_rxtx_vec_altivec.c
@@ -209,7 +209,8 @@ desc_to_olflags_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts)
 #define PKTLEN_SHIFT     10
 
 static inline void
-desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts)
+desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts,
+		uint32_t *ptype_tbl)
 {
 	vector unsigned long ptype0 = vec_mergel(descs[0], descs[1]);
 	vector unsigned long ptype1 = vec_mergel(descs[2], descs[3]);
@@ -217,14 +218,10 @@ desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts)
 	ptype0 = vec_sr(ptype0, (vector unsigned long){30, 30});
 	ptype1 = vec_sr(ptype1, (vector unsigned long){30, 30});
 
-	rx_pkts[0]->packet_type = i40e_rxd_pkt_type_mapping(
-					(*(vector unsigned char *)&ptype0)[0]);
-	rx_pkts[1]->packet_type = i40e_rxd_pkt_type_mapping(
-					(*(vector unsigned char *)&ptype0)[8]);
-	rx_pkts[2]->packet_type = i40e_rxd_pkt_type_mapping(
-					(*(vector unsigned char *)&ptype1)[0]);
-	rx_pkts[3]->packet_type = i40e_rxd_pkt_type_mapping(
-					(*(vector unsigned char *)&ptype1)[8]);
+	rx_pkts[0]->packet_type = ptype_tbl[(*(vector unsigned char *)&ptype0)[0])];
+	rx_pkts[1]->packet_type = ptype_tbl[(*(vector unsigned char *)&ptype0)[8])];
+	rx_pkts[2]->packet_type = ptype_tbl[(*(vector unsigned char *)&ptype1)[0])];
+	rx_pkts[3]->packet_type = ptype_tbl[(*(vector unsigned char *)&ptype1)[8])];
 }
 
  /* Notice:
@@ -242,6 +239,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 	int pos;
 	uint64_t var;
 	vector unsigned char shuf_msk;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	vector unsigned short crc_adjust = (vector unsigned short){
 		0, 0,         /* ignore pkt_type field */
@@ -466,7 +464,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 		vec_st(pkt_mb1, 0,
 		 (vector unsigned char *)&rx_pkts[pos]->rx_descriptor_fields1
 		);
-		desc_to_ptype_v(descs, &rx_pkts[pos]);
+		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
 		desc_to_olflags_v(descs, &rx_pkts[pos]);
 
 		/* C.4 calc avaialbe number of desc */
diff --git a/drivers/net/i40e/i40e_rxtx_vec_neon.c b/drivers/net/i40e/i40e_rxtx_vec_neon.c
index bd7239b..515931e 100644
--- a/drivers/net/i40e/i40e_rxtx_vec_neon.c
+++ b/drivers/net/i40e/i40e_rxtx_vec_neon.c
@@ -196,7 +196,8 @@ desc_to_olflags_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts)
 #define I40E_VPMD_DESC_DD_MASK	0x0001000100010001ULL
 
 static inline void
-desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts)
+desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts,
+		uint32_t *ptype_tbl)
 {
 	int i;
 	uint8_t ptype;
@@ -205,7 +206,7 @@ desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts)
 	for (i = 0; i < 4; i++) {
 		tmp = vreinterpretq_u8_u64(vshrq_n_u64(descs[i], 30));
 		ptype = vgetq_lane_u8(tmp, 8);
-		rx_pkts[i]->packet_type = i40e_rxd_pkt_type_mapping(ptype);
+		rx_pkts[i]->packet_type = ptype_tbl[ptype];
 	}
 
 }
@@ -225,6 +226,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 	uint16_t nb_pkts_recd;
 	int pos;
 	uint64_t var;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	/* mask to shuffle from desc. to mbuf */
 	uint8x16_t shuf_msk = {
@@ -429,7 +431,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 			 pkt_mb2);
 		vst1q_u8((void *)&rx_pkts[pos]->rx_descriptor_fields1,
 			 pkt_mb1);
-		desc_to_ptype_v(descs, &rx_pkts[pos]);
+		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
 		/* C.4 calc avaialbe number of desc */
 		var = __builtin_popcountll(stat & I40E_VPMD_DESC_DD_MASK);
 		nb_pkts_recd += var;
diff --git a/drivers/net/i40e/i40e_rxtx_vec_sse.c b/drivers/net/i40e/i40e_rxtx_vec_sse.c
index fdd4a34..335098a 100644
--- a/drivers/net/i40e/i40e_rxtx_vec_sse.c
+++ b/drivers/net/i40e/i40e_rxtx_vec_sse.c
@@ -215,7 +215,8 @@ desc_to_olflags_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
 #define PKTLEN_SHIFT     10
 
 static inline void
-desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
+desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts,
+		uint32_t *ptype_tbl)
 {
 	__m128i ptype0 = _mm_unpackhi_epi64(descs[0], descs[1]);
 	__m128i ptype1 = _mm_unpackhi_epi64(descs[2], descs[3]);
@@ -223,10 +224,10 @@ desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
 	ptype0 = _mm_srli_epi64(ptype0, 30);
 	ptype1 = _mm_srli_epi64(ptype1, 30);
 
-	rx_pkts[0]->packet_type = i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype0, 0));
-	rx_pkts[1]->packet_type = i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype0, 8));
-	rx_pkts[2]->packet_type = i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype1, 0));
-	rx_pkts[3]->packet_type = i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype1, 8));
+	rx_pkts[0]->packet_type = ptype_tbl[_mm_extract_epi8(ptype0, 0)];
+	rx_pkts[1]->packet_type = ptype_tbl[_mm_extract_epi8(ptype0, 8)];
+	rx_pkts[2]->packet_type = ptype_tbl[_mm_extract_epi8(ptype1, 0)];
+	rx_pkts[3]->packet_type = ptype_tbl[_mm_extract_epi8(ptype1, 8)];
 }
 
  /*
@@ -245,6 +246,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 	int pos;
 	uint64_t var;
 	__m128i shuf_msk;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	__m128i crc_adjust = _mm_set_epi16(
 				0, 0, 0,    /* ignore non-length fields */
@@ -432,7 +434,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 				 pkt_mb2);
 		_mm_storeu_si128((void *)&rx_pkts[pos]->rx_descriptor_fields1,
 				 pkt_mb1);
-		desc_to_ptype_v(descs, &rx_pkts[pos]);
+		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
 		/* C.4 calc avaialbe number of desc */
 		var = __builtin_popcountll(_mm_cvtsi128_si64(staterr));
 		nb_pkts_recd += var;
-- 
2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v8 2/3] net/i40e: configurable PTYPE mapping
  2017-04-07  3:25 ` [PATCH v8 " Qi Zhang
  2017-04-07  3:25   ` [PATCH v8 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
@ 2017-04-07  3:25   ` Qi Zhang
  2017-04-12  8:36     ` Ferruh Yigit
  2017-04-07  3:25   ` [PATCH v8 3/3] app/testpmd: add CL for ptype mapping configure Qi Zhang
  2017-04-12 13:55   ` [PATCH v9 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
  3 siblings, 1 reply; 21+ messages in thread
From: Qi Zhang @ 2017-04-07  3:25 UTC (permalink / raw)
  To: jingjing.wu, helin.zhang; +Cc: ferruh.yigit, jianbo.liu, chaozhu, dev, Qi Zhang

The patch adds 4 APIs to support configurable
PTYPE mapping for i40e device.
rte_pmd_i40e_ptype_mapping_get.
rte_pmd_i40e_ptype_mapping_replace.
rte_pmd_i40e_ptype_mapping_reset.
rte_pmd_i40e_ptype_mapping_update.
The mapping from hardware defined packet type to software defined packet
type can be updated/reset/read out with these APIs.
Also a software ptype with the most significent bit set will be regarded
as a user defined ptype (RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK) so
application can use it to defined its own PTYPE naming system.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---

v5:

- Rebase to dpdk-next-net

v4:

- Add comment to explain the "user defined" ptype.

v2:

- Rename APIs to rte_pmd_i40e_ptype_mapping_xxx

- Add missing API declaration in rte_pmd_i40e_version.map

- Add missing PTYPE in check_invalid_pkt_type

- Fix couple typo error

 drivers/net/i40e/i40e_ethdev.c            | 229 ++++++++++++++++++++++++++++++
 drivers/net/i40e/rte_pmd_i40e.h           |  86 +++++++++++
 drivers/net/i40e/rte_pmd_i40e_version.map |   4 +
 3 files changed, 319 insertions(+)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 2b95996..7ba9bed 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -12469,3 +12469,232 @@ i40e_init_log(void)
 	if (i40e_logtype_driver >= 0)
 		rte_log_set_level(i40e_logtype_driver, RTE_LOG_NOTICE);
 }
+
+static int check_invalid_pkt_type(uint32_t pkt_type)
+{
+	uint32_t l2, l3, l4, tnl, il2, il3, il4;
+
+	l2 = pkt_type & RTE_PTYPE_L2_MASK;
+	l3 = pkt_type & RTE_PTYPE_L3_MASK;
+	l4 = pkt_type & RTE_PTYPE_L4_MASK;
+	tnl = pkt_type & RTE_PTYPE_TUNNEL_MASK;
+	il2 = pkt_type & RTE_PTYPE_INNER_L2_MASK;
+	il3 = pkt_type & RTE_PTYPE_INNER_L3_MASK;
+	il4 = pkt_type & RTE_PTYPE_INNER_L4_MASK;
+
+	if (l2 &&
+	    l2 != RTE_PTYPE_L2_ETHER &&
+	    l2 != RTE_PTYPE_L2_ETHER_TIMESYNC &&
+	    l2 != RTE_PTYPE_L2_ETHER_ARP &&
+	    l2 != RTE_PTYPE_L2_ETHER_LLDP &&
+	    l2 != RTE_PTYPE_L2_ETHER_NSH &&
+	    l2 != RTE_PTYPE_L2_ETHER_VLAN &&
+	    l2 != RTE_PTYPE_L2_ETHER_QINQ)
+		return -1;
+
+	if (l3 &&
+	    l3 != RTE_PTYPE_L3_IPV4 &&
+	    l3 != RTE_PTYPE_L3_IPV4_EXT &&
+	    l3 != RTE_PTYPE_L3_IPV6 &&
+	    l3 != RTE_PTYPE_L3_IPV4_EXT_UNKNOWN &&
+	    l3 != RTE_PTYPE_L3_IPV6_EXT &&
+	    l3 != RTE_PTYPE_L3_IPV6_EXT_UNKNOWN)
+		return -1;
+
+	if (l4 &&
+	    l4 != RTE_PTYPE_L4_TCP &&
+	    l4 != RTE_PTYPE_L4_UDP &&
+	    l4 != RTE_PTYPE_L4_FRAG &&
+	    l4 != RTE_PTYPE_L4_SCTP &&
+	    l4 != RTE_PTYPE_L4_ICMP &&
+	    l4 != RTE_PTYPE_L4_NONFRAG)
+		return -1;
+
+	if (tnl &&
+	    tnl != RTE_PTYPE_TUNNEL_IP &&
+	    tnl != RTE_PTYPE_TUNNEL_GRENAT &&
+	    tnl != RTE_PTYPE_TUNNEL_VXLAN &&
+	    tnl != RTE_PTYPE_TUNNEL_NVGRE &&
+	    tnl != RTE_PTYPE_TUNNEL_GENEVE &&
+	    tnl != RTE_PTYPE_TUNNEL_GRENAT)
+		return -1;
+
+	if (il2 &&
+	    il2 != RTE_PTYPE_INNER_L2_ETHER &&
+	    il2 != RTE_PTYPE_INNER_L2_ETHER_VLAN &&
+	    il2 != RTE_PTYPE_INNER_L2_ETHER_QINQ)
+		return -1;
+
+	if (il3 &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV4 &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV4_EXT &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV6 &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV6_EXT &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN)
+		return -1;
+
+	if (il4 &&
+	    il4 != RTE_PTYPE_INNER_L4_TCP &&
+	    il4 != RTE_PTYPE_INNER_L4_UDP &&
+	    il4 != RTE_PTYPE_INNER_L4_FRAG &&
+	    il4 != RTE_PTYPE_INNER_L4_SCTP &&
+	    il4 != RTE_PTYPE_INNER_L4_ICMP &&
+	    il4 != RTE_PTYPE_INNER_L4_NONFRAG)
+		return -1;
+
+	return 0;
+}
+
+static int check_invalid_ptype_mapping(
+		struct rte_pmd_i40e_ptype_mapping *mapping_table,
+		uint16_t count)
+{
+	int i;
+
+	for (i = 0; i < count; i++) {
+		uint16_t ptype = mapping_table[i].hw_ptype;
+		uint32_t pkt_type = mapping_table[i].sw_ptype;
+
+		if (ptype >= I40E_MAX_PKT_TYPE)
+			return -1;
+
+		if (pkt_type == RTE_PTYPE_UNKNOWN)
+			continue;
+
+		if (pkt_type & RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK)
+			continue;
+
+		if (check_invalid_pkt_type(pkt_type))
+			return -1;
+	}
+
+	return 0;
+}
+
+int
+rte_pmd_i40e_ptype_mapping_update(
+			uint8_t port,
+			struct rte_pmd_i40e_ptype_mapping *mapping_items,
+			uint16_t count,
+			uint8_t exclusive)
+{
+	struct rte_eth_dev *dev;
+	struct i40e_adapter *ad;
+	int i;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	if (!is_device_supported(dev, &rte_i40e_pmd))
+		return -ENOTSUP;
+
+	if (count > I40E_MAX_PKT_TYPE)
+		return -EINVAL;
+
+	if (check_invalid_ptype_mapping(mapping_items, count))
+		return -EINVAL;
+
+	ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+	if (exclusive) {
+		for (i = 0; i < I40E_MAX_PKT_TYPE; i++)
+			ad->ptype_tbl[i] = RTE_PTYPE_UNKNOWN;
+	}
+
+	for (i = 0; i < count; i++)
+		ad->ptype_tbl[mapping_items[i].hw_ptype]
+			= mapping_items[i].sw_ptype;
+
+	return 0;
+}
+
+int rte_pmd_i40e_ptype_mapping_reset(uint8_t port)
+{
+	struct rte_eth_dev *dev;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	if (!is_device_supported(dev, &rte_i40e_pmd))
+		return -ENOTSUP;
+
+	i40e_set_default_ptype_table(dev);
+
+	return 0;
+}
+
+int rte_pmd_i40e_ptype_mapping_get(
+			uint8_t port,
+			struct rte_pmd_i40e_ptype_mapping *mapping_items,
+			uint16_t size,
+			uint16_t *count,
+			uint8_t valid_only)
+{
+	struct rte_eth_dev *dev;
+	struct i40e_adapter *ad;
+	int n = 0;
+	uint16_t i;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	if (!is_device_supported(dev, &rte_i40e_pmd))
+		return -ENOTSUP;
+
+	ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+	for (i = 0; i < I40E_MAX_PKT_TYPE; i++) {
+		if (n >= size)
+			break;
+		if (valid_only && ad->ptype_tbl[i] == RTE_PTYPE_UNKNOWN)
+			continue;
+		mapping_items[n].hw_ptype = i;
+		mapping_items[n].sw_ptype = ad->ptype_tbl[i];
+		n++;
+	}
+
+	*count = n;
+	return 0;
+}
+
+int rte_pmd_i40e_ptype_mapping_replace(uint8_t port,
+				       uint32_t target,
+				       uint8_t mask,
+				       uint32_t pkt_type)
+{
+	struct rte_eth_dev *dev;
+	struct i40e_adapter *ad;
+	uint16_t i;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	if (!is_device_supported(dev, &rte_i40e_pmd))
+		return -ENOTSUP;
+
+	if (!mask && check_invalid_pkt_type(target))
+		return -EINVAL;
+
+	if (check_invalid_pkt_type(pkt_type))
+		return -EINVAL;
+
+	ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+	for (i = 0; i < I40E_MAX_PKT_TYPE; i++) {
+		if (mask) {
+			if ((target | ad->ptype_tbl[i]) == target &&
+			    (target & ad->ptype_tbl[i]))
+				ad->ptype_tbl[i] = pkt_type;
+		} else {
+			if (ad->ptype_tbl[i] == target)
+				ad->ptype_tbl[i] = pkt_type;
+		}
+	}
+
+	return 0;
+}
diff --git a/drivers/net/i40e/rte_pmd_i40e.h b/drivers/net/i40e/rte_pmd_i40e.h
index 8e15630..f7b76f7 100644
--- a/drivers/net/i40e/rte_pmd_i40e.h
+++ b/drivers/net/i40e/rte_pmd_i40e.h
@@ -107,6 +107,18 @@ struct rte_pmd_i40e_profile_list {
 };
 
 /**
+ * ptype mapping table only accept RTE_PTYPE_XXX or "user defined" ptype.
+ * A ptype with MSB set will be regarded as a user defined ptype.
+ * Below macro help to create a user defined ptype.
+ */
+#define RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK 0x80000000
+
+struct rte_pmd_i40e_ptype_mapping {
+	uint16_t hw_ptype; /**< hardware defined packet type*/
+	uint32_t sw_ptype; /**< software defined packet type */
+};
+
+/**
  * Notify VF when PF link status changes.
  *
  * @param port
@@ -495,4 +507,78 @@ int rte_pmd_i40e_process_ddp_package(uint8_t port, uint8_t *buff,
  */
 int rte_pmd_i40e_get_ddp_list(uint8_t port, uint8_t *buff, uint32_t size);
 
+/**
+ * Update hardware defined ptype to software defined packet type
+ * mapping table.
+ *
+ * @param port
+ *    pointer to port identifier of the device.
+ * @param mapping_items
+ *    the base address of the mapping items array.
+ * @param count
+ *    number of mapping items.
+ * @param exclusive
+ *    the flag indicate different ptype mapping update method.
+ *    -(0) only overwrite referred PTYPE mapping,
+ *	keep other PTYPEs mapping unchanged.
+ *    -(!0) overwrite referred PTYPE mapping,
+ *	set other PTYPEs maps to PTYPE_UNKNOWN.
+ */
+int rte_pmd_i40e_ptype_mapping_update(
+			uint8_t port,
+			struct rte_pmd_i40e_ptype_mapping *mapping_items,
+			uint16_t count,
+			uint8_t exclusive);
+
+/**
+ * Reset hardware defined ptype to software defined ptype
+ * mapping table to default.
+ *
+ * @param port
+ *    pointer to port identifier of the device
+ */
+int rte_pmd_i40e_ptype_mapping_reset(uint8_t port);
+
+/**
+ * Get hardware defined ptype to software defined ptype
+ * mapping items.
+ *
+ * @param port
+ *    pointer to port identifier of the device.
+ * @param mapping_items
+ *    the base address of the array to store returned items.
+ * @param size
+ *    the size of the input array.
+ * @param count
+ *    the place to store the number of returned items.
+ * @param valid_only
+ *    -(0) return full mapping table.
+ *    -(!0) only return mapping items which packet_type != RTE_PTYPE_UNKNOWN.
+ */
+int rte_pmd_i40e_ptype_mapping_get(
+			uint8_t port,
+			struct rte_pmd_i40e_ptype_mapping *mapping_items,
+			uint16_t size,
+			uint16_t *count,
+			uint8_t valid_only);
+
+/**
+ * Replace a specific or a group of software defined ptypes
+ * with a new one
+ *
+ * @param port
+ *    pointer to port identifier of the device
+ * @param target
+ *    the packet type to be replaced
+ * @param mask
+ *    -(0) target represent a specific software defined ptype.
+ *    -(!0) target is a mask to represent a group of software defined ptypes.
+ * @param pkt_type
+ *    the new packet type to overwrite
+ */
+int rte_pmd_i40e_ptype_mapping_replace(uint8_t port,
+				       uint32_t target,
+				       uint8_t mask,
+				       uint32_t pkt_type);
+
 #endif /* _PMD_I40E_H_ */
diff --git a/drivers/net/i40e/rte_pmd_i40e_version.map b/drivers/net/i40e/rte_pmd_i40e_version.map
index dbb994e..3b0e805 100644
--- a/drivers/net/i40e/rte_pmd_i40e_version.map
+++ b/drivers/net/i40e/rte_pmd_i40e_version.map
@@ -8,6 +8,10 @@ DPDK_17.02 {
 
 	rte_pmd_i40e_get_vf_stats;
 	rte_pmd_i40e_ping_vfs;
+	rte_pmd_i40e_ptype_mapping_get;
+	rte_pmd_i40e_ptype_mapping_replace;
+	rte_pmd_i40e_ptype_mapping_reset;
+	rte_pmd_i40e_ptype_mapping_update;
 	rte_pmd_i40e_reset_vf_stats;
 	rte_pmd_i40e_set_tx_loopback;
 	rte_pmd_i40e_set_vf_broadcast;
-- 
2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v8 3/3] app/testpmd: add CL for ptype mapping configure
  2017-04-07  3:25 ` [PATCH v8 " Qi Zhang
  2017-04-07  3:25   ` [PATCH v8 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
  2017-04-07  3:25   ` [PATCH v8 2/3] net/i40e: configurable PTYPE mapping Qi Zhang
@ 2017-04-07  3:25   ` Qi Zhang
  2017-04-12 13:55   ` [PATCH v9 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
  3 siblings, 0 replies; 21+ messages in thread
From: Qi Zhang @ 2017-04-07  3:25 UTC (permalink / raw)
  To: jingjing.wu, helin.zhang; +Cc: ferruh.yigit, jianbo.liu, chaozhu, dev, Qi Zhang

Add below command line to configure ptype mapping.
ptype mapping get <port_id> <valid_only>.
ptype mapping replace <port_id> <target> <mask> <pkt_type>.
ptype mapping reset <port_id>.
ptype mapping update <port_id> <hw_ptype> <sw_ptype>.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---

v6:

- Update testpmd_func.rst.

v5:

- Rebase to dpdk-next-net

v3:

- Fix compile issue when CONFIG_RTE_LIBRTE_I40E_PMD=n

 app/test-pmd/cmdline.c                      | 372 ++++++++++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  36 +++
 2 files changed, 408 insertions(+)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index e0d54d4..f6bd75b 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -605,6 +605,18 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"ddp add (port_id) (profile_path)\n"
 			"    Load a profile package on a port\n\n"
 
+			"ptype mapping get (port_id) (valid_only)\n"
+			"    Get ptype mapping on a port\n\n"
+
+			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
+			"    Replace target with the pkt_type in ptype mapping\n\n"
+
+			"ptype mapping reset (port_id)\n"
+			"    Reset ptype mapping on a port\n\n"
+
+			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
+			"    Update a ptype mapping item on a port\n\n"
+
 			, list_pkt_forwarding_modes()
 		);
 	}
@@ -13161,6 +13173,362 @@ cmdline_parse_inst_t cmd_clear_vf_stats = {
 	},
 };
 
+/* ptype mapping get */
+
+/* Common result structure for ptype mapping get */
+struct cmd_ptype_mapping_get_result {
+	cmdline_fixed_string_t ptype;
+	cmdline_fixed_string_t mapping;
+	cmdline_fixed_string_t get;
+	uint8_t port_id;
+	uint8_t valid_only;
+};
+
+/* Common CLI fields for ptype mapping get */
+cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 ptype, "ptype");
+cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 mapping, "mapping");
+cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 get, "get");
+cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 port_id, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 valid_only, UINT8);
+
+static void
+cmd_ptype_mapping_get_parsed(
+	void *parsed_result,
+	__attribute__((unused)) struct cmdline *cl,
+	__attribute__((unused)) void *data)
+{
+	struct cmd_ptype_mapping_get_result *res = parsed_result;
+	int ret = -ENOTSUP;
+#ifdef RTE_LIBRTE_I40E_PMD
+	int max_ptype_num = 256;
+	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
+	uint16_t count;
+	int i;
+#endif
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
+					mapping,
+					max_ptype_num,
+					&count,
+					res->valid_only);
+#endif
+
+	switch (ret) {
+	case 0:
+		break;
+	case -ENODEV:
+		printf("invalid port_id %d\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		printf("function not implemented\n");
+		break;
+	default:
+		printf("programming error: (%s)\n", strerror(-ret));
+	}
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	if (!ret) {
+		for (i = 0; i < count; i++)
+			printf("%3d\t0x%08x\n",
+				mapping[i].hw_ptype, mapping[i].sw_ptype);
+	}
+#endif
+}
+
+cmdline_parse_inst_t cmd_ptype_mapping_get = {
+	.f = cmd_ptype_mapping_get_parsed,
+	.data = NULL,
+	.help_str = "ptype mapping get <port_id> <valid_only>",
+	.tokens = {
+		(void *)&cmd_ptype_mapping_get_ptype,
+		(void *)&cmd_ptype_mapping_get_mapping,
+		(void *)&cmd_ptype_mapping_get_get,
+		(void *)&cmd_ptype_mapping_get_port_id,
+		(void *)&cmd_ptype_mapping_get_valid_only,
+		NULL,
+	},
+};
+
+/* ptype mapping replace */
+
+/* Common result structure for ptype mapping replace */
+struct cmd_ptype_mapping_replace_result {
+	cmdline_fixed_string_t ptype;
+	cmdline_fixed_string_t mapping;
+	cmdline_fixed_string_t replace;
+	uint8_t port_id;
+	uint32_t target;
+	uint8_t mask;
+	uint32_t pkt_type;
+};
+
+/* Common CLI fields for ptype mapping replace */
+cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 ptype, "ptype");
+cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 mapping, "mapping");
+cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 replace, "replace");
+cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 port_id, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 target, UINT32);
+cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 mask, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 pkt_type, UINT32);
+
+static void
+cmd_ptype_mapping_replace_parsed(
+	void *parsed_result,
+	__attribute__((unused)) struct cmdline *cl,
+	__attribute__((unused)) void *data)
+{
+	struct cmd_ptype_mapping_replace_result *res = parsed_result;
+	int ret = -ENOTSUP;
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
+					res->target,
+					res->mask,
+					res->pkt_type);
+#endif
+
+	switch (ret) {
+	case 0:
+		break;
+	case -EINVAL:
+		printf("invalid ptype 0x%8x or 0x%8x\n",
+				res->target, res->pkt_type);
+		break;
+	case -ENODEV:
+		printf("invalid port_id %d\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		printf("function not implemented\n");
+		break;
+	default:
+		printf("programming error: (%s)\n", strerror(-ret));
+	}
+}
+
+cmdline_parse_inst_t cmd_ptype_mapping_replace = {
+	.f = cmd_ptype_mapping_replace_parsed,
+	.data = NULL,
+	.help_str =
+		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
+	.tokens = {
+		(void *)&cmd_ptype_mapping_replace_ptype,
+		(void *)&cmd_ptype_mapping_replace_mapping,
+		(void *)&cmd_ptype_mapping_replace_replace,
+		(void *)&cmd_ptype_mapping_replace_port_id,
+		(void *)&cmd_ptype_mapping_replace_target,
+		(void *)&cmd_ptype_mapping_replace_mask,
+		(void *)&cmd_ptype_mapping_replace_pkt_type,
+		NULL,
+	},
+};
+
+/* ptype mapping reset */
+
+/* Common result structure for ptype mapping reset */
+struct cmd_ptype_mapping_reset_result {
+	cmdline_fixed_string_t ptype;
+	cmdline_fixed_string_t mapping;
+	cmdline_fixed_string_t reset;
+	uint8_t port_id;
+};
+
+/* Common CLI fields for ptype mapping reset*/
+cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_reset_result,
+		 ptype, "ptype");
+cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_reset_result,
+		 mapping, "mapping");
+cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_reset_result,
+		 reset, "reset");
+cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_reset_result,
+		 port_id, UINT8);
+
+static void
+cmd_ptype_mapping_reset_parsed(
+	void *parsed_result,
+	__attribute__((unused)) struct cmdline *cl,
+	__attribute__((unused)) void *data)
+{
+	struct cmd_ptype_mapping_reset_result *res = parsed_result;
+	int ret = -ENOTSUP;
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
+#endif
+
+	switch (ret) {
+	case 0:
+		break;
+	case -ENODEV:
+		printf("invalid port_id %d\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		printf("function not implemented\n");
+		break;
+	default:
+		printf("programming error: (%s)\n", strerror(-ret));
+	}
+}
+
+cmdline_parse_inst_t cmd_ptype_mapping_reset = {
+	.f = cmd_ptype_mapping_reset_parsed,
+	.data = NULL,
+	.help_str = "ptype mapping reset <port_id>",
+	.tokens = {
+		(void *)&cmd_ptype_mapping_reset_ptype,
+		(void *)&cmd_ptype_mapping_reset_mapping,
+		(void *)&cmd_ptype_mapping_reset_reset,
+		(void *)&cmd_ptype_mapping_reset_port_id,
+		NULL,
+	},
+};
+
+/* ptype mapping update */
+
+/* Common result structure for ptype mapping update */
+struct cmd_ptype_mapping_update_result {
+	cmdline_fixed_string_t ptype;
+	cmdline_fixed_string_t mapping;
+	cmdline_fixed_string_t reset;
+	uint8_t port_id;
+	uint8_t hw_ptype;
+	uint32_t sw_ptype;
+};
+
+/* Common CLI fields for ptype mapping update*/
+cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 ptype, "ptype");
+cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 mapping, "mapping");
+cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 reset, "update");
+cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 port_id, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 hw_ptype, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 sw_ptype, UINT32);
+
+static void
+cmd_ptype_mapping_update_parsed(
+	void *parsed_result,
+	__attribute__((unused)) struct cmdline *cl,
+	__attribute__((unused)) void *data)
+{
+	struct cmd_ptype_mapping_update_result *res = parsed_result;
+	int ret = -ENOTSUP;
+#ifdef RTE_LIBRTE_I40E_PMD
+	struct rte_pmd_i40e_ptype_mapping mapping;
+#endif
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	mapping.hw_ptype = res->hw_ptype;
+	mapping.sw_ptype = res->sw_ptype;
+	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
+						&mapping,
+						1,
+						0);
+#endif
+
+	switch (ret) {
+	case 0:
+		break;
+	case -EINVAL:
+		printf("invalid ptype 0x%8x\n", res->sw_ptype);
+		break;
+	case -ENODEV:
+		printf("invalid port_id %d\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		printf("function not implemented\n");
+		break;
+	default:
+		printf("programming error: (%s)\n", strerror(-ret));
+	}
+}
+
+cmdline_parse_inst_t cmd_ptype_mapping_update = {
+	.f = cmd_ptype_mapping_update_parsed,
+	.data = NULL,
+	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
+	.tokens = {
+		(void *)&cmd_ptype_mapping_update_ptype,
+		(void *)&cmd_ptype_mapping_update_mapping,
+		(void *)&cmd_ptype_mapping_update_update,
+		(void *)&cmd_ptype_mapping_update_port_id,
+		(void *)&cmd_ptype_mapping_update_hw_ptype,
+		(void *)&cmd_ptype_mapping_update_sw_ptype,
+		NULL,
+	},
+};
+
 /* ******************************************************************************** */
 
 /* list of instructions */
@@ -13345,6 +13713,10 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
+	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
+	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
+	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
+	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
 	NULL,
 };
 
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 497e2dd..aa6ffa0 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -1156,6 +1156,42 @@ Add an E-tag forwarding filter on a port::
 Delete an E-tag forwarding filter on a port::
    testpmd> E-tag set filter del e-tag-id (value) port (port_id)
 
+ptype mapping
+~~~~~~~~~~~~~
+
+List all items from the ptype mapping table::
+
+   testpmd> ptype mapping get (port_id) (valid_only)
+
+Where:
+
+* ``valid_only``: A flag indicates if only list valid items(=1) or all itemss(=0).
+
+Replace a specific or a group of software defined ptype with a new one::
+
+   testpmd> ptype mapping replace  (port_id) (target) (mask) (pkt_type)
+
+where:
+
+* ``target``: A specific software ptype or a mask to represent a group of software ptypes.
+
+* ``mask``: A flag indicate if "target" is a specific software ptype(=0) or a ptype mask(=1).
+
+* ``pkt_type``: The new software ptype to replace the old ones.
+
+Update hardware defined ptype to software defined packet type mapping table::
+
+   testpmd> ptype mapping update (port_id) (hw_ptype) (sw_ptype)
+
+where:
+
+* ``hw_ptype``: hardware ptype as the index of the ptype mapping table.
+
+* ``sw_ptype``: software ptype as the value of the ptype mapping table.
+
+Reset ptype mapping table::
+
+   testpmd> ptype mapping reset (port_id)
 
 Port Functions
 --------------
-- 
2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v8 1/3] net/i40e: enable per dev PTYPE mapping table
  2017-04-07  2:36     ` Zhang, Qi Z
@ 2017-04-12  2:13       ` Zhang, Qi Z
  0 siblings, 0 replies; 21+ messages in thread
From: Zhang, Qi Z @ 2017-04-12  2:13 UTC (permalink / raw)
  To: 'chaozhu@linux.vnet.ibm.com'
  Cc: Yigit, Ferruh, 'jianbo.liu@linaro.org',
	'dev@dpdk.org',
	Wu, Jingjing, Zhang, Helin, Thomas Monjalon

Ping again.

> -----Original Message-----
> From: Zhang, Qi Z
> Sent: Friday, April 7, 2017 10:37 AM
> To: chaozhu@linux.vnet.ibm.com
> Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; jianbo.liu@linaro.org;
> dev@dpdk.org; Wu, Jingjing <jingjing.wu@intel.com>; Zhang, Helin
> <helin.zhang@intel.com>
> Subject: RE: [PATCH v8 1/3] net/i40e: enable per dev PTYPE mapping table
> 
> Hi Chao:
> 	Would you help to check the PowerPC part. (i40e_rxtx_vec_altivec.c)
> Thanks Qi
> 
> > -----Original Message-----
> > From: Zhang, Qi Z
> > Sent: Friday, April 7, 2017 11:25 AM
> > To: Wu, Jingjing <jingjing.wu@intel.com>; Zhang, Helin
> > <helin.zhang@intel.com>
> > Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; jianbo.liu@linaro.org;
> > chaozhu@linux.vnet.ibm.com; dev@dpdk.org; Zhang, Qi Z
> > <qi.z.zhang@intel.com>
> > Subject: [PATCH v8 1/3] net/i40e: enable per dev PTYPE mapping table
> >
> > The mapping from hardware defined packet type to software defined
> > packet type is static for i40e device, the patch let each ethdev to to
> > have their own copy of mapping table, this give the possibility that
> > different ethdev can be set different PTYPE mapping rule which is the
> > requirement to support following hardware's dynamic PTYPE feature.
> >
> > Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
> > ---
> >
> > v8:
> >
> > - Fix compile error for ARM vPMD.
> >
> > v7:
> >
> > - Add Altivec vPMD support.
> >
> > v5:
> >
> > - Rebase to dpdk-next-net
> >
> >  drivers/net/i40e/i40e_ethdev.c           |  1 +
> >  drivers/net/i40e/i40e_ethdev.h           |  5 +++++
> >  drivers/net/i40e/i40e_ethdev_vf.c        |  2 +-
> >  drivers/net/i40e/i40e_rxtx.c             | 30
> > ++++++++++++++++++++++--------
> >  drivers/net/i40e/i40e_rxtx.h             |  3 ++-
> >  drivers/net/i40e/i40e_rxtx_vec_altivec.c | 18 ++++++++----------
> >  drivers/net/i40e/i40e_rxtx_vec_neon.c    |  8 +++++---
> >  drivers/net/i40e/i40e_rxtx_vec_sse.c     | 14 ++++++++------
> >  8 files changed, 52 insertions(+), 29 deletions(-)
> >
> > diff --git a/drivers/net/i40e/i40e_ethdev.c
> > b/drivers/net/i40e/i40e_ethdev.c index 6927fde..2b95996 100644
> > --- a/drivers/net/i40e/i40e_ethdev.c
> > +++ b/drivers/net/i40e/i40e_ethdev.c
> > @@ -1065,6 +1065,7 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
> >  		i40e_set_tx_function(dev);
> >  		return 0;
> >  	}
> > +	i40e_set_default_ptype_table(dev);
> >  	pci_dev = I40E_DEV_TO_PCI(dev);
> >  	intr_handle = &pci_dev->intr_handle;
> >
> > diff --git a/drivers/net/i40e/i40e_ethdev.h
> > b/drivers/net/i40e/i40e_ethdev.h index 69c6684..a1535b0 100644
> > --- a/drivers/net/i40e/i40e_ethdev.h
> > +++ b/drivers/net/i40e/i40e_ethdev.h
> > @@ -744,6 +744,8 @@ struct i40e_vf {
> >  	uint64_t flags;
> >  };
> >
> > +#define I40E_MAX_PKT_TYPE 256
> > +
> >  /*
> >   * Structure to store private data for each PF/VF instance.
> >   */
> > @@ -768,6 +770,9 @@ struct i40e_adapter {
> >  	struct rte_timecounter systime_tc;
> >  	struct rte_timecounter rx_tstamp_tc;
> >  	struct rte_timecounter tx_tstamp_tc;
> > +
> > +	/* ptype mapping table */
> > +	uint32_t ptype_tbl[I40E_MAX_PKT_TYPE] __rte_cache_min_aligned;
> >  };
> >
> >  extern const struct rte_flow_ops i40e_flow_ops; diff --git
> > a/drivers/net/i40e/i40e_ethdev_vf.c
> > b/drivers/net/i40e/i40e_ethdev_vf.c
> > index 7e48fea..3db5b6f 100644
> > --- a/drivers/net/i40e/i40e_ethdev_vf.c
> > +++ b/drivers/net/i40e/i40e_ethdev_vf.c
> > @@ -1477,7 +1477,7 @@ i40evf_dev_init(struct rte_eth_dev *eth_dev)
> >  		i40e_set_tx_function(eth_dev);
> >  		return 0;
> >  	}
> > -
> > +	i40e_set_default_ptype_table(eth_dev);
> >  	rte_eth_copy_pci_info(eth_dev, pci_dev);
> >  	eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
> >
> > diff --git a/drivers/net/i40e/i40e_rxtx.c
> > b/drivers/net/i40e/i40e_rxtx.c index
> > ff70c06..e5471b1 100644
> > --- a/drivers/net/i40e/i40e_rxtx.c
> > +++ b/drivers/net/i40e/i40e_rxtx.c
> > @@ -61,7 +61,6 @@
> >
> >  #define DEFAULT_TX_RS_THRESH   32
> >  #define DEFAULT_TX_FREE_THRESH 32
> > -#define I40E_MAX_PKT_TYPE      256
> >
> >  #define I40E_TX_MAX_BURST  32
> >
> > @@ -458,6 +457,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
> >  	int32_t s[I40E_LOOK_AHEAD], nb_dd;
> >  	int32_t i, j, nb_rx = 0;
> >  	uint64_t pkt_flags;
> > +	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> >
> >  	rxdp = &rxq->rx_ring[rxq->rx_tail];
> >  	rxep = &rxq->sw_ring[rxq->rx_tail];
> > @@ -506,9 +506,9 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
> >  			pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
> >  			pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
> >  			mb->packet_type =
> > -				i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
> > -						I40E_RXD_QW1_PTYPE_MASK) >>
> > -						I40E_RXD_QW1_PTYPE_SHIFT));
> > +				ptype_tbl[(uint8_t)((qword1 &
> > +				I40E_RXD_QW1_PTYPE_MASK) >>
> > +				I40E_RXD_QW1_PTYPE_SHIFT)];
> >  			if (pkt_flags & PKT_RX_RSS_HASH)
> >  				mb->hash.rss = rte_le_to_cpu_32(\
> >  					rxdp[j].wb.qword0.hi_dword.rss); @@ -700,6 +700,7
> @@
> > i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t
> > nb_pkts)
> >  	uint16_t rx_id, nb_hold;
> >  	uint64_t dma_addr;
> >  	uint64_t pkt_flags;
> > +	uint32_t *ptype_tbl;
> >
> >  	nb_rx = 0;
> >  	nb_hold = 0;
> > @@ -707,6 +708,7 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf
> > **rx_pkts, uint16_t nb_pkts)
> >  	rx_id = rxq->rx_tail;
> >  	rx_ring = rxq->rx_ring;
> >  	sw_ring = rxq->sw_ring;
> > +	ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> >
> >  	while (nb_rx < nb_pkts) {
> >  		rxdp = &rx_ring[rx_id];
> > @@ -763,8 +765,8 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf
> > **rx_pkts, uint16_t nb_pkts)
> >  		pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
> >  		pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
> >  		rxm->packet_type =
> > -			i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
> > -			I40E_RXD_QW1_PTYPE_MASK) >>
> > I40E_RXD_QW1_PTYPE_SHIFT));
> > +			ptype_tbl[(uint8_t)((qword1 &
> > +			I40E_RXD_QW1_PTYPE_MASK) >>
> > I40E_RXD_QW1_PTYPE_SHIFT)];
> >  		if (pkt_flags & PKT_RX_RSS_HASH)
> >  			rxm->hash.rss =
> >  				rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
> > @@ -818,6 +820,7 @@ i40e_recv_scattered_pkts(void *rx_queue,
> >  	uint64_t qword1;
> >  	uint64_t dma_addr;
> >  	uint64_t pkt_flags;
> > +	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> >
> >  	while (nb_rx < nb_pkts) {
> >  		rxdp = &rx_ring[rx_id];
> > @@ -925,8 +928,8 @@ i40e_recv_scattered_pkts(void *rx_queue,
> >  		pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
> >  		pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
> >  		first_seg->packet_type =
> > -			i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
> > -			I40E_RXD_QW1_PTYPE_MASK) >>
> > I40E_RXD_QW1_PTYPE_SHIFT));
> > +			ptype_tbl[(uint8_t)((qword1 &
> > +			I40E_RXD_QW1_PTYPE_MASK) >>
> > I40E_RXD_QW1_PTYPE_SHIFT)];
> >  		if (pkt_flags & PKT_RX_RSS_HASH)
> >  			first_seg->hash.rss =
> >  				rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
> > @@ -2922,6 +2925,17 @@ i40e_set_tx_function(struct rte_eth_dev *dev)
> >  	}
> >  }
> >
> > +void __attribute__((cold))
> > +i40e_set_default_ptype_table(struct rte_eth_dev *dev) {
> > +	struct i40e_adapter *ad =
> > +		I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
> > +	int i;
> > +
> > +	for (i = 0; i <= I40E_MAX_PKT_TYPE; i++)
> > +		ad->ptype_tbl[i] = i40e_get_default_pkt_type(i); }
> > +
> >  /* Stubs needed for linkage when CONFIG_RTE_I40E_INC_VECTOR is set to
> > 'n' */  int __attribute__((weak))
> > i40e_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused
> > *dev) diff --git a/drivers/net/i40e/i40e_rxtx.h
> > b/drivers/net/i40e/i40e_rxtx.h index 2fa7f37..20084d6 100644
> > --- a/drivers/net/i40e/i40e_rxtx.h
> > +++ b/drivers/net/i40e/i40e_rxtx.h
> > @@ -254,13 +254,14 @@ void i40e_set_rx_function(struct rte_eth_dev
> > *dev);  void i40e_set_tx_function_flag(struct rte_eth_dev *dev,
> >  			       struct i40e_tx_queue *txq);  void
> > i40e_set_tx_function(struct rte_eth_dev *dev);
> > +void i40e_set_default_ptype_table(struct rte_eth_dev *dev);
> >
> >  /* For each value it means, datasheet of hardware can tell more details
> >   *
> >   * @note: fix i40e_dev_supported_ptypes_get() if any change here.
> >   */
> >  static inline uint32_t
> > -i40e_rxd_pkt_type_mapping(uint8_t ptype)
> > +i40e_get_default_pkt_type(uint8_t ptype)
> >  {
> >  	static const uint32_t type_table[UINT8_MAX + 1] __rte_cache_aligned
> > = {
> >  		/* L2 types */
> > diff --git a/drivers/net/i40e/i40e_rxtx_vec_altivec.c
> > b/drivers/net/i40e/i40e_rxtx_vec_altivec.c
> > index 2f6f70a..5f525ff 100644
> > --- a/drivers/net/i40e/i40e_rxtx_vec_altivec.c
> > +++ b/drivers/net/i40e/i40e_rxtx_vec_altivec.c
> > @@ -209,7 +209,8 @@ desc_to_olflags_v(vector unsigned long descs[4],
> > struct rte_mbuf **rx_pkts)
> >  #define PKTLEN_SHIFT     10
> >
> >  static inline void
> > -desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf
> > **rx_pkts)
> > +desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts,
> > +		uint32_t *ptype_tbl)
> >  {
> >  	vector unsigned long ptype0 = vec_mergel(descs[0], descs[1]);
> >  	vector unsigned long ptype1 = vec_mergel(descs[2], descs[3]); @@
> > -217,14 +218,10 @@ desc_to_ptype_v(vector unsigned long descs[4],
> > struct rte_mbuf **rx_pkts)
> >  	ptype0 = vec_sr(ptype0, (vector unsigned long){30, 30});
> >  	ptype1 = vec_sr(ptype1, (vector unsigned long){30, 30});
> >
> > -	rx_pkts[0]->packet_type = i40e_rxd_pkt_type_mapping(
> > -					(*(vector unsigned char *)&ptype0)[0]);
> > -	rx_pkts[1]->packet_type = i40e_rxd_pkt_type_mapping(
> > -					(*(vector unsigned char *)&ptype0)[8]);
> > -	rx_pkts[2]->packet_type = i40e_rxd_pkt_type_mapping(
> > -					(*(vector unsigned char *)&ptype1)[0]);
> > -	rx_pkts[3]->packet_type = i40e_rxd_pkt_type_mapping(
> > -					(*(vector unsigned char *)&ptype1)[8]);
> > +	rx_pkts[0]->packet_type = ptype_tbl[(*(vector unsigned char
> > *)&ptype0)[0])];
> > +	rx_pkts[1]->packet_type = ptype_tbl[(*(vector unsigned char
> > *)&ptype0)[8])];
> > +	rx_pkts[2]->packet_type = ptype_tbl[(*(vector unsigned char
> > *)&ptype1)[0])];
> > +	rx_pkts[3]->packet_type = ptype_tbl[(*(vector unsigned char
> > +*)&ptype1)[8])];
> >  }
> >
> >   /* Notice:
> > @@ -242,6 +239,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq,
> > struct rte_mbuf **rx_pkts,
> >  	int pos;
> >  	uint64_t var;
> >  	vector unsigned char shuf_msk;
> > +	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> >
> >  	vector unsigned short crc_adjust = (vector unsigned short){
> >  		0, 0,         /* ignore pkt_type field */
> > @@ -466,7 +464,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq,
> > struct rte_mbuf **rx_pkts,
> >  		vec_st(pkt_mb1, 0,
> >  		 (vector unsigned char *)&rx_pkts[pos]->rx_descriptor_fields1
> >  		);
> > -		desc_to_ptype_v(descs, &rx_pkts[pos]);
> > +		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
> >  		desc_to_olflags_v(descs, &rx_pkts[pos]);
> >
> >  		/* C.4 calc avaialbe number of desc */ diff --git
> > a/drivers/net/i40e/i40e_rxtx_vec_neon.c
> > b/drivers/net/i40e/i40e_rxtx_vec_neon.c
> > index bd7239b..515931e 100644
> > --- a/drivers/net/i40e/i40e_rxtx_vec_neon.c
> > +++ b/drivers/net/i40e/i40e_rxtx_vec_neon.c
> > @@ -196,7 +196,8 @@ desc_to_olflags_v(uint64x2_t descs[4], struct
> > rte_mbuf **rx_pkts)
> >  #define I40E_VPMD_DESC_DD_MASK	0x0001000100010001ULL
> >
> >  static inline void
> > -desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts)
> > +desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts,
> > +		uint32_t *ptype_tbl)
> >  {
> >  	int i;
> >  	uint8_t ptype;
> > @@ -205,7 +206,7 @@ desc_to_ptype_v(uint64x2_t descs[4], struct
> > rte_mbuf **rx_pkts)
> >  	for (i = 0; i < 4; i++) {
> >  		tmp = vreinterpretq_u8_u64(vshrq_n_u64(descs[i], 30));
> >  		ptype = vgetq_lane_u8(tmp, 8);
> > -		rx_pkts[i]->packet_type = i40e_rxd_pkt_type_mapping(ptype);
> > +		rx_pkts[i]->packet_type = ptype_tbl[ptype];
> >  	}
> >
> >  }
> > @@ -225,6 +226,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq,
> > struct rte_mbuf **rx_pkts,
> >  	uint16_t nb_pkts_recd;
> >  	int pos;
> >  	uint64_t var;
> > +	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> >
> >  	/* mask to shuffle from desc. to mbuf */
> >  	uint8x16_t shuf_msk = {
> > @@ -429,7 +431,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq,
> > struct rte_mbuf **rx_pkts,
> >  			 pkt_mb2);
> >  		vst1q_u8((void *)&rx_pkts[pos]->rx_descriptor_fields1,
> >  			 pkt_mb1);
> > -		desc_to_ptype_v(descs, &rx_pkts[pos]);
> > +		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
> >  		/* C.4 calc avaialbe number of desc */
> >  		var = __builtin_popcountll(stat & I40E_VPMD_DESC_DD_MASK);
> >  		nb_pkts_recd += var;
> > diff --git a/drivers/net/i40e/i40e_rxtx_vec_sse.c
> > b/drivers/net/i40e/i40e_rxtx_vec_sse.c
> > index fdd4a34..335098a 100644
> > --- a/drivers/net/i40e/i40e_rxtx_vec_sse.c
> > +++ b/drivers/net/i40e/i40e_rxtx_vec_sse.c
> > @@ -215,7 +215,8 @@ desc_to_olflags_v(__m128i descs[4], struct
> > rte_mbuf **rx_pkts)
> >  #define PKTLEN_SHIFT     10
> >
> >  static inline void
> > -desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
> > +desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts,
> > +		uint32_t *ptype_tbl)
> >  {
> >  	__m128i ptype0 = _mm_unpackhi_epi64(descs[0], descs[1]);
> >  	__m128i ptype1 = _mm_unpackhi_epi64(descs[2], descs[3]); @@
> > -223,10 +224,10 @@ desc_to_ptype_v(__m128i descs[4], struct rte_mbuf
> > **rx_pkts)
> >  	ptype0 = _mm_srli_epi64(ptype0, 30);
> >  	ptype1 = _mm_srli_epi64(ptype1, 30);
> >
> > -	rx_pkts[0]->packet_type =
> > i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype0, 0));
> > -	rx_pkts[1]->packet_type =
> > i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype0, 8));
> > -	rx_pkts[2]->packet_type =
> > i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype1, 0));
> > -	rx_pkts[3]->packet_type =
> > i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype1, 8));
> > +	rx_pkts[0]->packet_type = ptype_tbl[_mm_extract_epi8(ptype0, 0)];
> > +	rx_pkts[1]->packet_type = ptype_tbl[_mm_extract_epi8(ptype0, 8)];
> > +	rx_pkts[2]->packet_type = ptype_tbl[_mm_extract_epi8(ptype1, 0)];
> > +	rx_pkts[3]->packet_type = ptype_tbl[_mm_extract_epi8(ptype1, 8)];
> >  }
> >
> >   /*
> > @@ -245,6 +246,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq,
> > struct rte_mbuf **rx_pkts,
> >  	int pos;
> >  	uint64_t var;
> >  	__m128i shuf_msk;
> > +	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
> >
> >  	__m128i crc_adjust = _mm_set_epi16(
> >  				0, 0, 0,    /* ignore non-length fields */
> > @@ -432,7 +434,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq,
> > struct rte_mbuf **rx_pkts,
> >  				 pkt_mb2);
> >  		_mm_storeu_si128((void *)&rx_pkts[pos]->rx_descriptor_fields1,
> >  				 pkt_mb1);
> > -		desc_to_ptype_v(descs, &rx_pkts[pos]);
> > +		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
> >  		/* C.4 calc avaialbe number of desc */
> >  		var = __builtin_popcountll(_mm_cvtsi128_si64(staterr));
> >  		nb_pkts_recd += var;
> > --
> > 2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v8 2/3] net/i40e: configurable PTYPE mapping
  2017-04-07  3:25   ` [PATCH v8 2/3] net/i40e: configurable PTYPE mapping Qi Zhang
@ 2017-04-12  8:36     ` Ferruh Yigit
  0 siblings, 0 replies; 21+ messages in thread
From: Ferruh Yigit @ 2017-04-12  8:36 UTC (permalink / raw)
  To: Qi Zhang, jingjing.wu, helin.zhang; +Cc: jianbo.liu, chaozhu, dev

On 4/7/2017 4:25 AM, Qi Zhang wrote:
> The patch adds 4 APIs to support configurable
> PTYPE mapping for i40e device.
> rte_pmd_i40e_ptype_mapping_get.
> rte_pmd_i40e_ptype_mapping_replace.
> rte_pmd_i40e_ptype_mapping_reset.
> rte_pmd_i40e_ptype_mapping_update.
> The mapping from hardware defined packet type to software defined packet
> type can be updated/reset/read out with these APIs.
> Also a software ptype with the most significent bit set will be regarded
> as a user defined ptype (RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK) so
> application can use it to defined its own PTYPE naming system.
> 
> Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
> ---
> 
> v5:
> 
> - Rebase to dpdk-next-net
> 
> v4:
> 
> - Add comment to explain the "user defined" ptype.
> 
> v2:
> 
> - Rename APIs to rte_pmd_i40e_ptype_mapping_xxx
> 
> - Add missing API declaration in rte_pmd_i40e_version.map
> 
> - Add missing PTYPE in check_invalid_pkt_type
> 
> - Fix couple typo error
> 
>  drivers/net/i40e/i40e_ethdev.c            | 229 ++++++++++++++++++++++++++++++

Hi Qi,

These functions now needs to be moved to "rte_pmd_i40e.c". Can you
please rebase patch on top of latest next-net?

Thanks,
ferruh

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v9 0/3] net/i40e: configurable PTYPE mapping
  2017-04-07  3:25 ` [PATCH v8 " Qi Zhang
                     ` (2 preceding siblings ...)
  2017-04-07  3:25   ` [PATCH v8 3/3] app/testpmd: add CL for ptype mapping configure Qi Zhang
@ 2017-04-12 13:55   ` Qi Zhang
  2017-04-12 13:55     ` [PATCH v9 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
                       ` (3 more replies)
  3 siblings, 4 replies; 21+ messages in thread
From: Qi Zhang @ 2017-04-12 13:55 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: jingjing.wu, helin.zhang, jianbo.liu, chaozhu, dev, Qi Zhang

The patch set create new APIs that help to change the mapping from hardware
defined packet type to software defined packet type for i40e NICs.
Keep these APIs private is because currently they are only meaningful for
devices that support dynamic PTYPE configuration, which may not be a general
device feature.

v9:

- Rebase to dpdk-next-net

v8:

- Fix compile error on for ARM vPMD
- Rebase to 17.05-rc1

v7:

- Add Altivec vPMD support.

v6:

- Update testpmd_func.rst.

v5:

- Rebase to dpdk-next-net.

v4:

- Add comment to explain the "user defined" ptype.

v3:

- Fix compile error when CONFIG_RTE_LIBRTE_I40E_PMD=y in testpmd

v2:

- Add testpmd command line:
  ptype mapping get <port_id> <valid_only>
  ptype mapping replace <port_id> <target> <mask> <pkt_type>
  ptype mapping reset <port_id>
  ptype mapping update <port_id> <hw_ptype> <sw_ptype>

- Rename APIs to rte_pmd_i40e_ptype_mapping_xxx

- Add missing API declaration in rte_pmd_i40e_version.map

- Add missing ptype in check_invalid_pkt_type

- Fix couple typo error

Qi Zhang (3):
  net/i40e: enable per dev PTYPE mapping table
  net/i40e: configurable PTYPE mapping
  app/testpmd: add CL for ptype mapping configure

 app/test-pmd/cmdline.c                      | 372 ++++++++++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  36 +++
 drivers/net/i40e/i40e_ethdev.c              |   1 +
 drivers/net/i40e/i40e_ethdev.h              |   5 +
 drivers/net/i40e/i40e_ethdev_vf.c           |   2 +-
 drivers/net/i40e/i40e_rxtx.c                |  30 ++-
 drivers/net/i40e/i40e_rxtx.h                |   3 +-
 drivers/net/i40e/i40e_rxtx_vec_altivec.c    |  22 +-
 drivers/net/i40e/i40e_rxtx_vec_neon.c       |   8 +-
 drivers/net/i40e/i40e_rxtx_vec_sse.c        |  14 +-
 drivers/net/i40e/rte_pmd_i40e.c             | 230 +++++++++++++++++
 drivers/net/i40e/rte_pmd_i40e.h             |  86 +++++++
 drivers/net/i40e/rte_pmd_i40e_version.map   |   4 +
 13 files changed, 784 insertions(+), 29 deletions(-)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v9 1/3] net/i40e: enable per dev PTYPE mapping table
  2017-04-12 13:55   ` [PATCH v9 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
@ 2017-04-12 13:55     ` Qi Zhang
  2017-04-12 13:55     ` [PATCH v9 2/3] net/i40e: configurable PTYPE mapping Qi Zhang
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 21+ messages in thread
From: Qi Zhang @ 2017-04-12 13:55 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: jingjing.wu, helin.zhang, jianbo.liu, chaozhu, dev, Qi Zhang

The mapping from hardware defined packet type to software defined
packet type is static for i40e device, the patch let each ethdev to
to have their own copy of mapping table, this give the possibility
that different ethdev can be set different PTYPE mapping rule which
is the requirement to support following hardware's dynamic PTYPE
feature.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---

v8:

- Fix compile error for ARM vPMD.

v7:

- Add Altivec vPMD support.

v5:

- Rebase to dpdk-next-net

 drivers/net/i40e/i40e_ethdev.c           |  1 +
 drivers/net/i40e/i40e_ethdev.h           |  5 +++++
 drivers/net/i40e/i40e_ethdev_vf.c        |  2 +-
 drivers/net/i40e/i40e_rxtx.c             | 30 ++++++++++++++++++++++--------
 drivers/net/i40e/i40e_rxtx.h             |  3 ++-
 drivers/net/i40e/i40e_rxtx_vec_altivec.c | 22 ++++++++++++----------
 drivers/net/i40e/i40e_rxtx_vec_neon.c    |  8 +++++---
 drivers/net/i40e/i40e_rxtx_vec_sse.c     | 14 ++++++++------
 8 files changed, 56 insertions(+), 29 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 59c603f..107ce44 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -1051,6 +1051,7 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
 		i40e_set_tx_function(dev);
 		return 0;
 	}
+	i40e_set_default_ptype_table(dev);
 	pci_dev = I40E_DEV_TO_PCI(dev);
 	intr_handle = &pci_dev->intr_handle;
 
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index c745e9b..71b0874 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -744,6 +744,8 @@ struct i40e_vf {
 	uint64_t flags;
 };
 
+#define I40E_MAX_PKT_TYPE 256
+
 /*
  * Structure to store private data for each PF/VF instance.
  */
@@ -768,6 +770,9 @@ struct i40e_adapter {
 	struct rte_timecounter systime_tc;
 	struct rte_timecounter rx_tstamp_tc;
 	struct rte_timecounter tx_tstamp_tc;
+
+	/* ptype mapping table */
+	uint32_t ptype_tbl[I40E_MAX_PKT_TYPE] __rte_cache_min_aligned;
 };
 
 extern const struct rte_flow_ops i40e_flow_ops;
diff --git a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c
index a307109..12c95a6 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -1477,7 +1477,7 @@ i40evf_dev_init(struct rte_eth_dev *eth_dev)
 		i40e_set_tx_function(eth_dev);
 		return 0;
 	}
-
+	i40e_set_default_ptype_table(eth_dev);
 	rte_eth_copy_pci_info(eth_dev, pci_dev);
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
 
diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c
index ff70c06..e5471b1 100644
--- a/drivers/net/i40e/i40e_rxtx.c
+++ b/drivers/net/i40e/i40e_rxtx.c
@@ -61,7 +61,6 @@
 
 #define DEFAULT_TX_RS_THRESH   32
 #define DEFAULT_TX_FREE_THRESH 32
-#define I40E_MAX_PKT_TYPE      256
 
 #define I40E_TX_MAX_BURST  32
 
@@ -458,6 +457,7 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 	int32_t s[I40E_LOOK_AHEAD], nb_dd;
 	int32_t i, j, nb_rx = 0;
 	uint64_t pkt_flags;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	rxdp = &rxq->rx_ring[rxq->rx_tail];
 	rxep = &rxq->sw_ring[rxq->rx_tail];
@@ -506,9 +506,9 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
 			pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
 			pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
 			mb->packet_type =
-				i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
-						I40E_RXD_QW1_PTYPE_MASK) >>
-						I40E_RXD_QW1_PTYPE_SHIFT));
+				ptype_tbl[(uint8_t)((qword1 &
+				I40E_RXD_QW1_PTYPE_MASK) >>
+				I40E_RXD_QW1_PTYPE_SHIFT)];
 			if (pkt_flags & PKT_RX_RSS_HASH)
 				mb->hash.rss = rte_le_to_cpu_32(\
 					rxdp[j].wb.qword0.hi_dword.rss);
@@ -700,6 +700,7 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	uint16_t rx_id, nb_hold;
 	uint64_t dma_addr;
 	uint64_t pkt_flags;
+	uint32_t *ptype_tbl;
 
 	nb_rx = 0;
 	nb_hold = 0;
@@ -707,6 +708,7 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	rx_id = rxq->rx_tail;
 	rx_ring = rxq->rx_ring;
 	sw_ring = rxq->sw_ring;
+	ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	while (nb_rx < nb_pkts) {
 		rxdp = &rx_ring[rx_id];
@@ -763,8 +765,8 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 		pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
 		pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
 		rxm->packet_type =
-			i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
-			I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT));
+			ptype_tbl[(uint8_t)((qword1 &
+			I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
 		if (pkt_flags & PKT_RX_RSS_HASH)
 			rxm->hash.rss =
 				rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
@@ -818,6 +820,7 @@ i40e_recv_scattered_pkts(void *rx_queue,
 	uint64_t qword1;
 	uint64_t dma_addr;
 	uint64_t pkt_flags;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	while (nb_rx < nb_pkts) {
 		rxdp = &rx_ring[rx_id];
@@ -925,8 +928,8 @@ i40e_recv_scattered_pkts(void *rx_queue,
 		pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
 		pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
 		first_seg->packet_type =
-			i40e_rxd_pkt_type_mapping((uint8_t)((qword1 &
-			I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT));
+			ptype_tbl[(uint8_t)((qword1 &
+			I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
 		if (pkt_flags & PKT_RX_RSS_HASH)
 			first_seg->hash.rss =
 				rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
@@ -2922,6 +2925,17 @@ i40e_set_tx_function(struct rte_eth_dev *dev)
 	}
 }
 
+void __attribute__((cold))
+i40e_set_default_ptype_table(struct rte_eth_dev *dev)
+{
+	struct i40e_adapter *ad =
+		I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+	int i;
+
+	for (i = 0; i <= I40E_MAX_PKT_TYPE; i++)
+		ad->ptype_tbl[i] = i40e_get_default_pkt_type(i);
+}
+
 /* Stubs needed for linkage when CONFIG_RTE_I40E_INC_VECTOR is set to 'n' */
 int __attribute__((weak))
 i40e_rx_vec_dev_conf_condition_check(struct rte_eth_dev __rte_unused *dev)
diff --git a/drivers/net/i40e/i40e_rxtx.h b/drivers/net/i40e/i40e_rxtx.h
index 2fa7f37..20084d6 100644
--- a/drivers/net/i40e/i40e_rxtx.h
+++ b/drivers/net/i40e/i40e_rxtx.h
@@ -254,13 +254,14 @@ void i40e_set_rx_function(struct rte_eth_dev *dev);
 void i40e_set_tx_function_flag(struct rte_eth_dev *dev,
 			       struct i40e_tx_queue *txq);
 void i40e_set_tx_function(struct rte_eth_dev *dev);
+void i40e_set_default_ptype_table(struct rte_eth_dev *dev);
 
 /* For each value it means, datasheet of hardware can tell more details
  *
  * @note: fix i40e_dev_supported_ptypes_get() if any change here.
  */
 static inline uint32_t
-i40e_rxd_pkt_type_mapping(uint8_t ptype)
+i40e_get_default_pkt_type(uint8_t ptype)
 {
 	static const uint32_t type_table[UINT8_MAX + 1] __rte_cache_aligned = {
 		/* L2 types */
diff --git a/drivers/net/i40e/i40e_rxtx_vec_altivec.c b/drivers/net/i40e/i40e_rxtx_vec_altivec.c
index 9831438..07de31b 100644
--- a/drivers/net/i40e/i40e_rxtx_vec_altivec.c
+++ b/drivers/net/i40e/i40e_rxtx_vec_altivec.c
@@ -198,7 +198,8 @@ desc_to_olflags_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts)
 #define PKTLEN_SHIFT     10
 
 static inline void
-desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts)
+desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts,
+		uint32_t *ptype_tbl)
 {
 	vector unsigned long ptype0 = vec_mergel(descs[0], descs[1]);
 	vector unsigned long ptype1 = vec_mergel(descs[2], descs[3]);
@@ -206,14 +207,14 @@ desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts)
 	ptype0 = vec_sr(ptype0, (vector unsigned long){30, 30});
 	ptype1 = vec_sr(ptype1, (vector unsigned long){30, 30});
 
-	rx_pkts[0]->packet_type = i40e_rxd_pkt_type_mapping(
-					(*(vector unsigned char *)&ptype0)[0]);
-	rx_pkts[1]->packet_type = i40e_rxd_pkt_type_mapping(
-					(*(vector unsigned char *)&ptype0)[8]);
-	rx_pkts[2]->packet_type = i40e_rxd_pkt_type_mapping(
-					(*(vector unsigned char *)&ptype1)[0]);
-	rx_pkts[3]->packet_type = i40e_rxd_pkt_type_mapping(
-					(*(vector unsigned char *)&ptype1)[8]);
+	rx_pkts[0]->packet_type =
+		ptype_tbl[(*(vector unsigned char *)&ptype0)[0])];
+	rx_pkts[1]->packet_type =
+		ptype_tbl[(*(vector unsigned char *)&ptype0)[8])];
+	rx_pkts[2]->packet_type =
+		ptype_tbl[(*(vector unsigned char *)&ptype1)[0])];
+	rx_pkts[3]->packet_type =
+		ptype_tbl[(*(vector unsigned char *)&ptype1)[8])];
 }
 
  /* Notice:
@@ -231,6 +232,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 	int pos;
 	uint64_t var;
 	vector unsigned char shuf_msk;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	vector unsigned short crc_adjust = (vector unsigned short){
 		0, 0,         /* ignore pkt_type field */
@@ -455,7 +457,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 		vec_st(pkt_mb1, 0,
 		 (vector unsigned char *)&rx_pkts[pos]->rx_descriptor_fields1
 		);
-		desc_to_ptype_v(descs, &rx_pkts[pos]);
+		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
 		desc_to_olflags_v(descs, &rx_pkts[pos]);
 
 		/* C.4 calc avaialbe number of desc */
diff --git a/drivers/net/i40e/i40e_rxtx_vec_neon.c b/drivers/net/i40e/i40e_rxtx_vec_neon.c
index ca6b1f4..694e91f 100644
--- a/drivers/net/i40e/i40e_rxtx_vec_neon.c
+++ b/drivers/net/i40e/i40e_rxtx_vec_neon.c
@@ -201,7 +201,8 @@ desc_to_olflags_v(struct i40e_rx_queue *rxq, uint64x2_t descs[4],
 #define I40E_VPMD_DESC_DD_MASK	0x0001000100010001ULL
 
 static inline void
-desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts)
+desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts,
+		uint32_t *ptype_tbl)
 {
 	int i;
 	uint8_t ptype;
@@ -210,7 +211,7 @@ desc_to_ptype_v(uint64x2_t descs[4], struct rte_mbuf **rx_pkts)
 	for (i = 0; i < 4; i++) {
 		tmp = vreinterpretq_u8_u64(vshrq_n_u64(descs[i], 30));
 		ptype = vgetq_lane_u8(tmp, 8);
-		rx_pkts[i]->packet_type = i40e_rxd_pkt_type_mapping(ptype);
+		rx_pkts[i]->packet_type = ptype_tbl[ptype];
 	}
 
 }
@@ -230,6 +231,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 	uint16_t nb_pkts_recd;
 	int pos;
 	uint64_t var;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	/* mask to shuffle from desc. to mbuf */
 	uint8x16_t shuf_msk = {
@@ -434,7 +436,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 			 pkt_mb2);
 		vst1q_u8((void *)&rx_pkts[pos]->rx_descriptor_fields1,
 			 pkt_mb1);
-		desc_to_ptype_v(descs, &rx_pkts[pos]);
+		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
 		/* C.4 calc avaialbe number of desc */
 		var = __builtin_popcountll(stat & I40E_VPMD_DESC_DD_MASK);
 		nb_pkts_recd += var;
diff --git a/drivers/net/i40e/i40e_rxtx_vec_sse.c b/drivers/net/i40e/i40e_rxtx_vec_sse.c
index f91e32d..8bc3399 100644
--- a/drivers/net/i40e/i40e_rxtx_vec_sse.c
+++ b/drivers/net/i40e/i40e_rxtx_vec_sse.c
@@ -212,7 +212,8 @@ desc_to_olflags_v(struct i40e_rx_queue *rxq, __m128i descs[4] __rte_unused,
 #define PKTLEN_SHIFT     10
 
 static inline void
-desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
+desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts,
+		uint32_t *ptype_tbl)
 {
 	__m128i ptype0 = _mm_unpackhi_epi64(descs[0], descs[1]);
 	__m128i ptype1 = _mm_unpackhi_epi64(descs[2], descs[3]);
@@ -220,10 +221,10 @@ desc_to_ptype_v(__m128i descs[4], struct rte_mbuf **rx_pkts)
 	ptype0 = _mm_srli_epi64(ptype0, 30);
 	ptype1 = _mm_srli_epi64(ptype1, 30);
 
-	rx_pkts[0]->packet_type = i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype0, 0));
-	rx_pkts[1]->packet_type = i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype0, 8));
-	rx_pkts[2]->packet_type = i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype1, 0));
-	rx_pkts[3]->packet_type = i40e_rxd_pkt_type_mapping(_mm_extract_epi8(ptype1, 8));
+	rx_pkts[0]->packet_type = ptype_tbl[_mm_extract_epi8(ptype0, 0)];
+	rx_pkts[1]->packet_type = ptype_tbl[_mm_extract_epi8(ptype0, 8)];
+	rx_pkts[2]->packet_type = ptype_tbl[_mm_extract_epi8(ptype1, 0)];
+	rx_pkts[3]->packet_type = ptype_tbl[_mm_extract_epi8(ptype1, 8)];
 }
 
  /*
@@ -242,6 +243,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 	int pos;
 	uint64_t var;
 	__m128i shuf_msk;
+	uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
 
 	__m128i crc_adjust = _mm_set_epi16(
 				0, 0, 0,    /* ignore non-length fields */
@@ -429,7 +431,7 @@ _recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
 				 pkt_mb2);
 		_mm_storeu_si128((void *)&rx_pkts[pos]->rx_descriptor_fields1,
 				 pkt_mb1);
-		desc_to_ptype_v(descs, &rx_pkts[pos]);
+		desc_to_ptype_v(descs, &rx_pkts[pos], ptype_tbl);
 		/* C.4 calc avaialbe number of desc */
 		var = __builtin_popcountll(_mm_cvtsi128_si64(staterr));
 		nb_pkts_recd += var;
-- 
2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v9 2/3] net/i40e: configurable PTYPE mapping
  2017-04-12 13:55   ` [PATCH v9 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
  2017-04-12 13:55     ` [PATCH v9 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
@ 2017-04-12 13:55     ` Qi Zhang
  2017-04-12 13:55     ` [PATCH v9 3/3] app/testpmd: add CL for ptype mapping configure Qi Zhang
  2017-04-13  9:50     ` [PATCH v9 0/3] net/i40e: configurable PTYPE mapping Chao Zhu
  3 siblings, 0 replies; 21+ messages in thread
From: Qi Zhang @ 2017-04-12 13:55 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: jingjing.wu, helin.zhang, jianbo.liu, chaozhu, dev, Qi Zhang

The patch adds 4 APIs to support configurable
PTYPE mapping for i40e device.
rte_pmd_i40e_ptype_mapping_get.
rte_pmd_i40e_ptype_mapping_replace.
rte_pmd_i40e_ptype_mapping_reset.
rte_pmd_i40e_ptype_mapping_update.
The mapping from hardware defined packet type to software defined packet
type can be updated/reset/read out with these APIs.
Also a software ptype with the most significent bit set will be regarded
as a user defined ptype (RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK) so
application can use it to defined its own PTYPE naming system.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---

v9:

- Rebase to dpdk-next-net again.

v5:

- Rebase to dpdk-next-net

v4:

- Add comment to explain the "user defined" ptype.

v2:

- Rename APIs to rte_pmd_i40e_ptype_mapping_xxx

- Add missing API declaration in rte_pmd_i40e_version.map

- Add missing PTYPE in check_invalid_pkt_type

- Fix couple typo error

 drivers/net/i40e/rte_pmd_i40e.c           | 230 ++++++++++++++++++++++++++++++
 drivers/net/i40e/rte_pmd_i40e.h           |  86 +++++++++++
 drivers/net/i40e/rte_pmd_i40e_version.map |   4 +
 3 files changed, 320 insertions(+)

diff --git a/drivers/net/i40e/rte_pmd_i40e.c b/drivers/net/i40e/rte_pmd_i40e.c
index cee067b..f7ce62b 100644
--- a/drivers/net/i40e/rte_pmd_i40e.c
+++ b/drivers/net/i40e/rte_pmd_i40e.c
@@ -37,6 +37,7 @@
 #include "base/i40e_prototype.h"
 #include "i40e_ethdev.h"
 #include "i40e_pf.h"
+#include "i40e_rxtx.h"
 #include "rte_pmd_i40e.h"
 
 /* The max bandwidth of i40e is 40Gbps. */
@@ -1705,3 +1706,232 @@ rte_pmd_i40e_get_ddp_list(uint8_t port, uint8_t *buff, uint32_t size)
 
 	return status;
 }
+
+static int check_invalid_pkt_type(uint32_t pkt_type)
+{
+	uint32_t l2, l3, l4, tnl, il2, il3, il4;
+
+	l2 = pkt_type & RTE_PTYPE_L2_MASK;
+	l3 = pkt_type & RTE_PTYPE_L3_MASK;
+	l4 = pkt_type & RTE_PTYPE_L4_MASK;
+	tnl = pkt_type & RTE_PTYPE_TUNNEL_MASK;
+	il2 = pkt_type & RTE_PTYPE_INNER_L2_MASK;
+	il3 = pkt_type & RTE_PTYPE_INNER_L3_MASK;
+	il4 = pkt_type & RTE_PTYPE_INNER_L4_MASK;
+
+	if (l2 &&
+	    l2 != RTE_PTYPE_L2_ETHER &&
+	    l2 != RTE_PTYPE_L2_ETHER_TIMESYNC &&
+	    l2 != RTE_PTYPE_L2_ETHER_ARP &&
+	    l2 != RTE_PTYPE_L2_ETHER_LLDP &&
+	    l2 != RTE_PTYPE_L2_ETHER_NSH &&
+	    l2 != RTE_PTYPE_L2_ETHER_VLAN &&
+	    l2 != RTE_PTYPE_L2_ETHER_QINQ)
+		return -1;
+
+	if (l3 &&
+	    l3 != RTE_PTYPE_L3_IPV4 &&
+	    l3 != RTE_PTYPE_L3_IPV4_EXT &&
+	    l3 != RTE_PTYPE_L3_IPV6 &&
+	    l3 != RTE_PTYPE_L3_IPV4_EXT_UNKNOWN &&
+	    l3 != RTE_PTYPE_L3_IPV6_EXT &&
+	    l3 != RTE_PTYPE_L3_IPV6_EXT_UNKNOWN)
+		return -1;
+
+	if (l4 &&
+	    l4 != RTE_PTYPE_L4_TCP &&
+	    l4 != RTE_PTYPE_L4_UDP &&
+	    l4 != RTE_PTYPE_L4_FRAG &&
+	    l4 != RTE_PTYPE_L4_SCTP &&
+	    l4 != RTE_PTYPE_L4_ICMP &&
+	    l4 != RTE_PTYPE_L4_NONFRAG)
+		return -1;
+
+	if (tnl &&
+	    tnl != RTE_PTYPE_TUNNEL_IP &&
+	    tnl != RTE_PTYPE_TUNNEL_GRENAT &&
+	    tnl != RTE_PTYPE_TUNNEL_VXLAN &&
+	    tnl != RTE_PTYPE_TUNNEL_NVGRE &&
+	    tnl != RTE_PTYPE_TUNNEL_GENEVE &&
+	    tnl != RTE_PTYPE_TUNNEL_GRENAT)
+		return -1;
+
+	if (il2 &&
+	    il2 != RTE_PTYPE_INNER_L2_ETHER &&
+	    il2 != RTE_PTYPE_INNER_L2_ETHER_VLAN &&
+	    il2 != RTE_PTYPE_INNER_L2_ETHER_QINQ)
+		return -1;
+
+	if (il3 &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV4 &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV4_EXT &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV6 &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV6_EXT &&
+	    il3 != RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN)
+		return -1;
+
+	if (il4 &&
+	    il4 != RTE_PTYPE_INNER_L4_TCP &&
+	    il4 != RTE_PTYPE_INNER_L4_UDP &&
+	    il4 != RTE_PTYPE_INNER_L4_FRAG &&
+	    il4 != RTE_PTYPE_INNER_L4_SCTP &&
+	    il4 != RTE_PTYPE_INNER_L4_ICMP &&
+	    il4 != RTE_PTYPE_INNER_L4_NONFRAG)
+		return -1;
+
+	return 0;
+}
+
+static int check_invalid_ptype_mapping(
+		struct rte_pmd_i40e_ptype_mapping *mapping_table,
+		uint16_t count)
+{
+	int i;
+
+	for (i = 0; i < count; i++) {
+		uint16_t ptype = mapping_table[i].hw_ptype;
+		uint32_t pkt_type = mapping_table[i].sw_ptype;
+
+		if (ptype >= I40E_MAX_PKT_TYPE)
+			return -1;
+
+		if (pkt_type == RTE_PTYPE_UNKNOWN)
+			continue;
+
+		if (pkt_type & RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK)
+			continue;
+
+		if (check_invalid_pkt_type(pkt_type))
+			return -1;
+	}
+
+	return 0;
+}
+
+int
+rte_pmd_i40e_ptype_mapping_update(
+			uint8_t port,
+			struct rte_pmd_i40e_ptype_mapping *mapping_items,
+			uint16_t count,
+			uint8_t exclusive)
+{
+	struct rte_eth_dev *dev;
+	struct i40e_adapter *ad;
+	int i;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	if (!is_i40e_supported(dev))
+		return -ENOTSUP;
+
+	if (count > I40E_MAX_PKT_TYPE)
+		return -EINVAL;
+
+	if (check_invalid_ptype_mapping(mapping_items, count))
+		return -EINVAL;
+
+	ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+	if (exclusive) {
+		for (i = 0; i < I40E_MAX_PKT_TYPE; i++)
+			ad->ptype_tbl[i] = RTE_PTYPE_UNKNOWN;
+	}
+
+	for (i = 0; i < count; i++)
+		ad->ptype_tbl[mapping_items[i].hw_ptype]
+			= mapping_items[i].sw_ptype;
+
+	return 0;
+}
+
+int rte_pmd_i40e_ptype_mapping_reset(uint8_t port)
+{
+	struct rte_eth_dev *dev;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	if (!is_i40e_supported(dev))
+		return -ENOTSUP;
+
+	i40e_set_default_ptype_table(dev);
+
+	return 0;
+}
+
+int rte_pmd_i40e_ptype_mapping_get(
+			uint8_t port,
+			struct rte_pmd_i40e_ptype_mapping *mapping_items,
+			uint16_t size,
+			uint16_t *count,
+			uint8_t valid_only)
+{
+	struct rte_eth_dev *dev;
+	struct i40e_adapter *ad;
+	int n = 0;
+	uint16_t i;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	if (!is_i40e_supported(dev))
+		return -ENOTSUP;
+
+	ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+	for (i = 0; i < I40E_MAX_PKT_TYPE; i++) {
+		if (n >= size)
+			break;
+		if (valid_only && ad->ptype_tbl[i] == RTE_PTYPE_UNKNOWN)
+			continue;
+		mapping_items[n].hw_ptype = i;
+		mapping_items[n].sw_ptype = ad->ptype_tbl[i];
+		n++;
+	}
+
+	*count = n;
+	return 0;
+}
+
+int rte_pmd_i40e_ptype_mapping_replace(uint8_t port,
+				       uint32_t target,
+				       uint8_t mask,
+				       uint32_t pkt_type)
+{
+	struct rte_eth_dev *dev;
+	struct i40e_adapter *ad;
+	uint16_t i;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	if (!is_i40e_supported(dev))
+		return -ENOTSUP;
+
+	if (!mask && check_invalid_pkt_type(target))
+		return -EINVAL;
+
+	if (check_invalid_pkt_type(pkt_type))
+		return -EINVAL;
+
+	ad = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+	for (i = 0; i < I40E_MAX_PKT_TYPE; i++) {
+		if (mask) {
+			if ((target | ad->ptype_tbl[i]) == target &&
+			    (target & ad->ptype_tbl[i]))
+				ad->ptype_tbl[i] = pkt_type;
+		} else {
+			if (ad->ptype_tbl[i] == target)
+				ad->ptype_tbl[i] = pkt_type;
+		}
+	}
+
+	return 0;
+}
diff --git a/drivers/net/i40e/rte_pmd_i40e.h b/drivers/net/i40e/rte_pmd_i40e.h
index 8e15630..f7b76f7 100644
--- a/drivers/net/i40e/rte_pmd_i40e.h
+++ b/drivers/net/i40e/rte_pmd_i40e.h
@@ -107,6 +107,18 @@ struct rte_pmd_i40e_profile_list {
 };
 
 /**
+ * ptype mapping table only accept RTE_PTYPE_XXX or "user defined" ptype.
+ * A ptype with MSB set will be regarded as a user defined ptype.
+ * Below macro help to create a user defined ptype.
+ */
+#define RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK 0x80000000
+
+struct rte_pmd_i40e_ptype_mapping {
+	uint16_t hw_ptype; /**< hardware defined packet type*/
+	uint32_t sw_ptype; /**< software defined packet type */
+};
+
+/**
  * Notify VF when PF link status changes.
  *
  * @param port
@@ -495,4 +507,78 @@ int rte_pmd_i40e_process_ddp_package(uint8_t port, uint8_t *buff,
  */
 int rte_pmd_i40e_get_ddp_list(uint8_t port, uint8_t *buff, uint32_t size);
 
+/**
+ * Update hardware defined ptype to software defined packet type
+ * mapping table.
+ *
+ * @param port
+ *    pointer to port identifier of the device.
+ * @param mapping_items
+ *    the base address of the mapping items array.
+ * @param count
+ *    number of mapping items.
+ * @param exclusive
+ *    the flag indicate different ptype mapping update method.
+ *    -(0) only overwrite referred PTYPE mapping,
+ *	keep other PTYPEs mapping unchanged.
+ *    -(!0) overwrite referred PTYPE mapping,
+ *	set other PTYPEs maps to PTYPE_UNKNOWN.
+ */
+int rte_pmd_i40e_ptype_mapping_update(
+			uint8_t port,
+			struct rte_pmd_i40e_ptype_mapping *mapping_items,
+			uint16_t count,
+			uint8_t exclusive);
+
+/**
+ * Reset hardware defined ptype to software defined ptype
+ * mapping table to default.
+ *
+ * @param port
+ *    pointer to port identifier of the device
+ */
+int rte_pmd_i40e_ptype_mapping_reset(uint8_t port);
+
+/**
+ * Get hardware defined ptype to software defined ptype
+ * mapping items.
+ *
+ * @param port
+ *    pointer to port identifier of the device.
+ * @param mapping_items
+ *    the base address of the array to store returned items.
+ * @param size
+ *    the size of the input array.
+ * @param count
+ *    the place to store the number of returned items.
+ * @param valid_only
+ *    -(0) return full mapping table.
+ *    -(!0) only return mapping items which packet_type != RTE_PTYPE_UNKNOWN.
+ */
+int rte_pmd_i40e_ptype_mapping_get(
+			uint8_t port,
+			struct rte_pmd_i40e_ptype_mapping *mapping_items,
+			uint16_t size,
+			uint16_t *count,
+			uint8_t valid_only);
+
+/**
+ * Replace a specific or a group of software defined ptypes
+ * with a new one
+ *
+ * @param port
+ *    pointer to port identifier of the device
+ * @param target
+ *    the packet type to be replaced
+ * @param mask
+ *    -(0) target represent a specific software defined ptype.
+ *    -(!0) target is a mask to represent a group of software defined ptypes.
+ * @param pkt_type
+ *    the new packet type to overwrite
+ */
+int rte_pmd_i40e_ptype_mapping_replace(uint8_t port,
+				       uint32_t target,
+				       uint8_t mask,
+				       uint32_t pkt_type);
+
 #endif /* _PMD_I40E_H_ */
diff --git a/drivers/net/i40e/rte_pmd_i40e_version.map b/drivers/net/i40e/rte_pmd_i40e_version.map
index dbb994e..3b0e805 100644
--- a/drivers/net/i40e/rte_pmd_i40e_version.map
+++ b/drivers/net/i40e/rte_pmd_i40e_version.map
@@ -8,6 +8,10 @@ DPDK_17.02 {
 
 	rte_pmd_i40e_get_vf_stats;
 	rte_pmd_i40e_ping_vfs;
+	rte_pmd_i40e_ptype_mapping_get;
+	rte_pmd_i40e_ptype_mapping_replace;
+	rte_pmd_i40e_ptype_mapping_reset;
+	rte_pmd_i40e_ptype_mapping_update;
 	rte_pmd_i40e_reset_vf_stats;
 	rte_pmd_i40e_set_tx_loopback;
 	rte_pmd_i40e_set_vf_broadcast;
-- 
2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v9 3/3] app/testpmd: add CL for ptype mapping configure
  2017-04-12 13:55   ` [PATCH v9 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
  2017-04-12 13:55     ` [PATCH v9 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
  2017-04-12 13:55     ` [PATCH v9 2/3] net/i40e: configurable PTYPE mapping Qi Zhang
@ 2017-04-12 13:55     ` Qi Zhang
  2017-04-13  9:50     ` [PATCH v9 0/3] net/i40e: configurable PTYPE mapping Chao Zhu
  3 siblings, 0 replies; 21+ messages in thread
From: Qi Zhang @ 2017-04-12 13:55 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: jingjing.wu, helin.zhang, jianbo.liu, chaozhu, dev, Qi Zhang

Add below command line to configure ptype mapping.
ptype mapping get <port_id> <valid_only>.
ptype mapping replace <port_id> <target> <mask> <pkt_type>.
ptype mapping reset <port_id>.
ptype mapping update <port_id> <hw_ptype> <sw_ptype>.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---

v6:

- Update testpmd_func.rst.

v5:

- Rebase to dpdk-next-net

v3:

- Fix compile issue when CONFIG_RTE_LIBRTE_I40E_PMD=n

 app/test-pmd/cmdline.c                      | 372 ++++++++++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  36 +++
 2 files changed, 408 insertions(+)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index e0d54d4..f6bd75b 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -605,6 +605,18 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"ddp add (port_id) (profile_path)\n"
 			"    Load a profile package on a port\n\n"
 
+			"ptype mapping get (port_id) (valid_only)\n"
+			"    Get ptype mapping on a port\n\n"
+
+			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
+			"    Replace target with the pkt_type in ptype mapping\n\n"
+
+			"ptype mapping reset (port_id)\n"
+			"    Reset ptype mapping on a port\n\n"
+
+			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
+			"    Update a ptype mapping item on a port\n\n"
+
 			, list_pkt_forwarding_modes()
 		);
 	}
@@ -13161,6 +13173,362 @@ cmdline_parse_inst_t cmd_clear_vf_stats = {
 	},
 };
 
+/* ptype mapping get */
+
+/* Common result structure for ptype mapping get */
+struct cmd_ptype_mapping_get_result {
+	cmdline_fixed_string_t ptype;
+	cmdline_fixed_string_t mapping;
+	cmdline_fixed_string_t get;
+	uint8_t port_id;
+	uint8_t valid_only;
+};
+
+/* Common CLI fields for ptype mapping get */
+cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 ptype, "ptype");
+cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 mapping, "mapping");
+cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 get, "get");
+cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 port_id, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_get_result,
+		 valid_only, UINT8);
+
+static void
+cmd_ptype_mapping_get_parsed(
+	void *parsed_result,
+	__attribute__((unused)) struct cmdline *cl,
+	__attribute__((unused)) void *data)
+{
+	struct cmd_ptype_mapping_get_result *res = parsed_result;
+	int ret = -ENOTSUP;
+#ifdef RTE_LIBRTE_I40E_PMD
+	int max_ptype_num = 256;
+	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
+	uint16_t count;
+	int i;
+#endif
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
+					mapping,
+					max_ptype_num,
+					&count,
+					res->valid_only);
+#endif
+
+	switch (ret) {
+	case 0:
+		break;
+	case -ENODEV:
+		printf("invalid port_id %d\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		printf("function not implemented\n");
+		break;
+	default:
+		printf("programming error: (%s)\n", strerror(-ret));
+	}
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	if (!ret) {
+		for (i = 0; i < count; i++)
+			printf("%3d\t0x%08x\n",
+				mapping[i].hw_ptype, mapping[i].sw_ptype);
+	}
+#endif
+}
+
+cmdline_parse_inst_t cmd_ptype_mapping_get = {
+	.f = cmd_ptype_mapping_get_parsed,
+	.data = NULL,
+	.help_str = "ptype mapping get <port_id> <valid_only>",
+	.tokens = {
+		(void *)&cmd_ptype_mapping_get_ptype,
+		(void *)&cmd_ptype_mapping_get_mapping,
+		(void *)&cmd_ptype_mapping_get_get,
+		(void *)&cmd_ptype_mapping_get_port_id,
+		(void *)&cmd_ptype_mapping_get_valid_only,
+		NULL,
+	},
+};
+
+/* ptype mapping replace */
+
+/* Common result structure for ptype mapping replace */
+struct cmd_ptype_mapping_replace_result {
+	cmdline_fixed_string_t ptype;
+	cmdline_fixed_string_t mapping;
+	cmdline_fixed_string_t replace;
+	uint8_t port_id;
+	uint32_t target;
+	uint8_t mask;
+	uint32_t pkt_type;
+};
+
+/* Common CLI fields for ptype mapping replace */
+cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 ptype, "ptype");
+cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 mapping, "mapping");
+cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 replace, "replace");
+cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 port_id, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 target, UINT32);
+cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 mask, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_replace_result,
+		 pkt_type, UINT32);
+
+static void
+cmd_ptype_mapping_replace_parsed(
+	void *parsed_result,
+	__attribute__((unused)) struct cmdline *cl,
+	__attribute__((unused)) void *data)
+{
+	struct cmd_ptype_mapping_replace_result *res = parsed_result;
+	int ret = -ENOTSUP;
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
+					res->target,
+					res->mask,
+					res->pkt_type);
+#endif
+
+	switch (ret) {
+	case 0:
+		break;
+	case -EINVAL:
+		printf("invalid ptype 0x%8x or 0x%8x\n",
+				res->target, res->pkt_type);
+		break;
+	case -ENODEV:
+		printf("invalid port_id %d\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		printf("function not implemented\n");
+		break;
+	default:
+		printf("programming error: (%s)\n", strerror(-ret));
+	}
+}
+
+cmdline_parse_inst_t cmd_ptype_mapping_replace = {
+	.f = cmd_ptype_mapping_replace_parsed,
+	.data = NULL,
+	.help_str =
+		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
+	.tokens = {
+		(void *)&cmd_ptype_mapping_replace_ptype,
+		(void *)&cmd_ptype_mapping_replace_mapping,
+		(void *)&cmd_ptype_mapping_replace_replace,
+		(void *)&cmd_ptype_mapping_replace_port_id,
+		(void *)&cmd_ptype_mapping_replace_target,
+		(void *)&cmd_ptype_mapping_replace_mask,
+		(void *)&cmd_ptype_mapping_replace_pkt_type,
+		NULL,
+	},
+};
+
+/* ptype mapping reset */
+
+/* Common result structure for ptype mapping reset */
+struct cmd_ptype_mapping_reset_result {
+	cmdline_fixed_string_t ptype;
+	cmdline_fixed_string_t mapping;
+	cmdline_fixed_string_t reset;
+	uint8_t port_id;
+};
+
+/* Common CLI fields for ptype mapping reset*/
+cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_reset_result,
+		 ptype, "ptype");
+cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_reset_result,
+		 mapping, "mapping");
+cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_reset_result,
+		 reset, "reset");
+cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_reset_result,
+		 port_id, UINT8);
+
+static void
+cmd_ptype_mapping_reset_parsed(
+	void *parsed_result,
+	__attribute__((unused)) struct cmdline *cl,
+	__attribute__((unused)) void *data)
+{
+	struct cmd_ptype_mapping_reset_result *res = parsed_result;
+	int ret = -ENOTSUP;
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
+#endif
+
+	switch (ret) {
+	case 0:
+		break;
+	case -ENODEV:
+		printf("invalid port_id %d\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		printf("function not implemented\n");
+		break;
+	default:
+		printf("programming error: (%s)\n", strerror(-ret));
+	}
+}
+
+cmdline_parse_inst_t cmd_ptype_mapping_reset = {
+	.f = cmd_ptype_mapping_reset_parsed,
+	.data = NULL,
+	.help_str = "ptype mapping reset <port_id>",
+	.tokens = {
+		(void *)&cmd_ptype_mapping_reset_ptype,
+		(void *)&cmd_ptype_mapping_reset_mapping,
+		(void *)&cmd_ptype_mapping_reset_reset,
+		(void *)&cmd_ptype_mapping_reset_port_id,
+		NULL,
+	},
+};
+
+/* ptype mapping update */
+
+/* Common result structure for ptype mapping update */
+struct cmd_ptype_mapping_update_result {
+	cmdline_fixed_string_t ptype;
+	cmdline_fixed_string_t mapping;
+	cmdline_fixed_string_t reset;
+	uint8_t port_id;
+	uint8_t hw_ptype;
+	uint32_t sw_ptype;
+};
+
+/* Common CLI fields for ptype mapping update*/
+cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 ptype, "ptype");
+cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 mapping, "mapping");
+cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 reset, "update");
+cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 port_id, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 hw_ptype, UINT8);
+cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_ptype_mapping_update_result,
+		 sw_ptype, UINT32);
+
+static void
+cmd_ptype_mapping_update_parsed(
+	void *parsed_result,
+	__attribute__((unused)) struct cmdline *cl,
+	__attribute__((unused)) void *data)
+{
+	struct cmd_ptype_mapping_update_result *res = parsed_result;
+	int ret = -ENOTSUP;
+#ifdef RTE_LIBRTE_I40E_PMD
+	struct rte_pmd_i40e_ptype_mapping mapping;
+#endif
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+#ifdef RTE_LIBRTE_I40E_PMD
+	mapping.hw_ptype = res->hw_ptype;
+	mapping.sw_ptype = res->sw_ptype;
+	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
+						&mapping,
+						1,
+						0);
+#endif
+
+	switch (ret) {
+	case 0:
+		break;
+	case -EINVAL:
+		printf("invalid ptype 0x%8x\n", res->sw_ptype);
+		break;
+	case -ENODEV:
+		printf("invalid port_id %d\n", res->port_id);
+		break;
+	case -ENOTSUP:
+		printf("function not implemented\n");
+		break;
+	default:
+		printf("programming error: (%s)\n", strerror(-ret));
+	}
+}
+
+cmdline_parse_inst_t cmd_ptype_mapping_update = {
+	.f = cmd_ptype_mapping_update_parsed,
+	.data = NULL,
+	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
+	.tokens = {
+		(void *)&cmd_ptype_mapping_update_ptype,
+		(void *)&cmd_ptype_mapping_update_mapping,
+		(void *)&cmd_ptype_mapping_update_update,
+		(void *)&cmd_ptype_mapping_update_port_id,
+		(void *)&cmd_ptype_mapping_update_hw_ptype,
+		(void *)&cmd_ptype_mapping_update_sw_ptype,
+		NULL,
+	},
+};
+
 /* ******************************************************************************** */
 
 /* list of instructions */
@@ -13345,6 +13713,10 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
+	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
+	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
+	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
+	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
 	NULL,
 };
 
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 6b8fc17..e1bcf27 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -1156,6 +1156,42 @@ Add an E-tag forwarding filter on a port::
 Delete an E-tag forwarding filter on a port::
    testpmd> E-tag set filter del e-tag-id (value) port (port_id)
 
+ptype mapping
+~~~~~~~~~~~~~
+
+List all items from the ptype mapping table::
+
+   testpmd> ptype mapping get (port_id) (valid_only)
+
+Where:
+
+* ``valid_only``: A flag indicates if only list valid items(=1) or all itemss(=0).
+
+Replace a specific or a group of software defined ptype with a new one::
+
+   testpmd> ptype mapping replace  (port_id) (target) (mask) (pkt_type)
+
+where:
+
+* ``target``: A specific software ptype or a mask to represent a group of software ptypes.
+
+* ``mask``: A flag indicate if "target" is a specific software ptype(=0) or a ptype mask(=1).
+
+* ``pkt_type``: The new software ptype to replace the old ones.
+
+Update hardware defined ptype to software defined packet type mapping table::
+
+   testpmd> ptype mapping update (port_id) (hw_ptype) (sw_ptype)
+
+where:
+
+* ``hw_ptype``: hardware ptype as the index of the ptype mapping table.
+
+* ``sw_ptype``: software ptype as the value of the ptype mapping table.
+
+Reset ptype mapping table::
+
+   testpmd> ptype mapping reset (port_id)
 
 Port Functions
 --------------
-- 
2.9.3

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v9 0/3] net/i40e: configurable PTYPE mapping
  2017-04-12 13:55   ` [PATCH v9 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
                       ` (2 preceding siblings ...)
  2017-04-12 13:55     ` [PATCH v9 3/3] app/testpmd: add CL for ptype mapping configure Qi Zhang
@ 2017-04-13  9:50     ` Chao Zhu
  2017-04-13 10:46       ` Ferruh Yigit
  3 siblings, 1 reply; 21+ messages in thread
From: Chao Zhu @ 2017-04-13  9:50 UTC (permalink / raw)
  To: 'Qi Zhang', ferruh.yigit
  Cc: jingjing.wu, helin.zhang, jianbo.liu, dev

> -----Original Message-----
> From: Qi Zhang [mailto:qi.z.zhang@intel.com]
> Sent: 2017年4月12日 21:56
> To: ferruh.yigit@intel.com
> Cc: jingjing.wu@intel.com; helin.zhang@intel.com; jianbo.liu@linaro.org;
> chaozhu@linux.vnet.ibm.com; dev@dpdk.org; Qi Zhang <qi.z.zhang@intel.com>
> Subject: [PATCH v9 0/3] net/i40e: configurable PTYPE mapping
> 
> The patch set create new APIs that help to change the mapping from
hardware
> defined packet type to software defined packet type for i40e NICs.
> Keep these APIs private is because currently they are only meaningful for
> devices that support dynamic PTYPE configuration, which may not be a
general
> device feature.
> 
> v9:
> 
> - Rebase to dpdk-next-net
> 
> v8:
> 
> - Fix compile error on for ARM vPMD
> - Rebase to 17.05-rc1
> 
> v7:
> 
> - Add Altivec vPMD support.
> 
> v6:
> 
> - Update testpmd_func.rst.
> 
> v5:
> 
> - Rebase to dpdk-next-net.
> 
> v4:
> 
> - Add comment to explain the "user defined" ptype.
> 
> v3:
> 
> - Fix compile error when CONFIG_RTE_LIBRTE_I40E_PMD=y in testpmd
> 
> v2:
> 
> - Add testpmd command line:
>   ptype mapping get <port_id> <valid_only>
>   ptype mapping replace <port_id> <target> <mask> <pkt_type>
>   ptype mapping reset <port_id>
>   ptype mapping update <port_id> <hw_ptype> <sw_ptype>
> 
> - Rename APIs to rte_pmd_i40e_ptype_mapping_xxx
> 
> - Add missing API declaration in rte_pmd_i40e_version.map
> 
> - Add missing ptype in check_invalid_pkt_type
> 
> - Fix couple typo error
> 
> Qi Zhang (3):
>   net/i40e: enable per dev PTYPE mapping table
>   net/i40e: configurable PTYPE mapping
>   app/testpmd: add CL for ptype mapping configure
> 
>  app/test-pmd/cmdline.c                      | 372
> ++++++++++++++++++++++++++++
>  doc/guides/testpmd_app_ug/testpmd_funcs.rst |  36 +++
>  drivers/net/i40e/i40e_ethdev.c              |   1 +
>  drivers/net/i40e/i40e_ethdev.h              |   5 +
>  drivers/net/i40e/i40e_ethdev_vf.c           |   2 +-
>  drivers/net/i40e/i40e_rxtx.c                |  30 ++-
>  drivers/net/i40e/i40e_rxtx.h                |   3 +-
>  drivers/net/i40e/i40e_rxtx_vec_altivec.c    |  22 +-
>  drivers/net/i40e/i40e_rxtx_vec_neon.c       |   8 +-
>  drivers/net/i40e/i40e_rxtx_vec_sse.c        |  14 +-
>  drivers/net/i40e/rte_pmd_i40e.c             | 230 +++++++++++++++++
>  drivers/net/i40e/rte_pmd_i40e.h             |  86 +++++++
>  drivers/net/i40e/rte_pmd_i40e_version.map   |   4 +
>  13 files changed, 784 insertions(+), 29 deletions(-)
> 
> --
> 2.9.3
Acked-by: Chao Zhu <chaozhu@linux.vnet.ibm.com>

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v9 0/3] net/i40e: configurable PTYPE mapping
  2017-04-13  9:50     ` [PATCH v9 0/3] net/i40e: configurable PTYPE mapping Chao Zhu
@ 2017-04-13 10:46       ` Ferruh Yigit
  0 siblings, 0 replies; 21+ messages in thread
From: Ferruh Yigit @ 2017-04-13 10:46 UTC (permalink / raw)
  To: Chao Zhu, 'Qi Zhang'; +Cc: jingjing.wu, helin.zhang, jianbo.liu, dev

On 4/13/2017 10:50 AM, Chao Zhu wrote:
>> -----Original Message-----
>> From: Qi Zhang [mailto:qi.z.zhang@intel.com]
>> Sent: 2017年4月12日 21:56
>> To: ferruh.yigit@intel.com
>> Cc: jingjing.wu@intel.com; helin.zhang@intel.com; jianbo.liu@linaro.org;
>> chaozhu@linux.vnet.ibm.com; dev@dpdk.org; Qi Zhang <qi.z.zhang@intel.com>
>> Subject: [PATCH v9 0/3] net/i40e: configurable PTYPE mapping
>>
>> The patch set create new APIs that help to change the mapping from
> hardware
>> defined packet type to software defined packet type for i40e NICs.
>> Keep these APIs private is because currently they are only meaningful for
>> devices that support dynamic PTYPE configuration, which may not be a
> general
>> device feature.

<...>

>> Qi Zhang (3):
>>   net/i40e: enable per dev PTYPE mapping table
>>   net/i40e: configurable PTYPE mapping
>>   app/testpmd: add CL for ptype mapping configure

Acked-by: Jianbo Liu <jianbo.liu@linaro.org>

> Acked-by: Chao Zhu <chaozhu@linux.vnet.ibm.com>

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

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2017-04-13 10:46 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-04  1:55 [PATCH v7 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
2017-04-04  1:55 ` [PATCH v7 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
2017-04-04  1:55 ` [PATCH v7 2/3] net/i40e: configurable PTYPE mapping Qi Zhang
2017-04-04  1:55 ` [PATCH v7 3/3] app/testpmd: add CL for ptype mapping configure Qi Zhang
2017-04-04  9:30 ` [PATCH v7 0/3] net/i40e: configurable PTYPE mapping Ferruh Yigit
2017-04-04 20:22   ` Thomas Monjalon
2017-04-05  5:45     ` Jianbo Liu
2017-04-05  6:01       ` Zhang, Qi Z
2017-04-07  3:25 ` [PATCH v8 " Qi Zhang
2017-04-07  3:25   ` [PATCH v8 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
2017-04-07  2:36     ` Zhang, Qi Z
2017-04-12  2:13       ` Zhang, Qi Z
2017-04-07  3:25   ` [PATCH v8 2/3] net/i40e: configurable PTYPE mapping Qi Zhang
2017-04-12  8:36     ` Ferruh Yigit
2017-04-07  3:25   ` [PATCH v8 3/3] app/testpmd: add CL for ptype mapping configure Qi Zhang
2017-04-12 13:55   ` [PATCH v9 0/3] net/i40e: configurable PTYPE mapping Qi Zhang
2017-04-12 13:55     ` [PATCH v9 1/3] net/i40e: enable per dev PTYPE mapping table Qi Zhang
2017-04-12 13:55     ` [PATCH v9 2/3] net/i40e: configurable PTYPE mapping Qi Zhang
2017-04-12 13:55     ` [PATCH v9 3/3] app/testpmd: add CL for ptype mapping configure Qi Zhang
2017-04-13  9:50     ` [PATCH v9 0/3] net/i40e: configurable PTYPE mapping Chao Zhu
2017-04-13 10:46       ` Ferruh Yigit

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.