Blame SOURCES/net-i40e-implement-vector-PMD-for-altivec.patch

95b418
From 6fd9dc71febe68f4033a6330e6c9bb03610ba1ac Mon Sep 17 00:00:00 2001
95b418
From: Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
95b418
Date: Wed, 3 May 2017 11:55:58 +0530
95b418
Subject: [PATCH 1/2] net/i40e: implement vector PMD for altivec
95b418
95b418
This patch enables i40e driver in PowerPC along with its altivec
95b418
intrinsic support.
95b418
95b418
Signed-off-by: Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
95b418
Acked-by: Chao Zhu <chaozhu@linux.vnet.ibm.com>
95b418
---
95b418
 MAINTAINERS                                 |   1 +
95b418
 config/defconfig_ppc_64-power8-linuxapp-gcc |   1 -
95b418
 doc/guides/nics/features/i40e.ini           |   1 +
95b418
 doc/guides/nics/features/i40e_vec.ini       |   1 +
95b418
 doc/guides/rel_notes/release_16_11.rst      |   3 +
95b418
 drivers/net/i40e/Makefile                   |   2 +
95b418
 drivers/net/i40e/i40e_rxtx_vec_altivec.c    | 654 ++++++++++++++++++++++++++++
95b418
 7 files changed, 662 insertions(+), 1 deletion(-)
95b418
 create mode 100644 drivers/net/i40e/i40e_rxtx_vec_altivec.c
95b418
95b418
diff --git a/MAINTAINERS b/MAINTAINERS
95b418
index 065397b..a380b5d 100644
95b418
--- a/MAINTAINERS
95b418
+++ b/MAINTAINERS
95b418
@@ -166,6 +166,7 @@ IBM POWER
95b418
 M: Chao Zhu <chaozhu@linux.vnet.ibm.com>
95b418
 F: lib/librte_eal/common/arch/ppc_64/
95b418
 F: lib/librte_eal/common/include/arch/ppc_64/
95b418
+F: drivers/net/i40e/i40e_rxtx_vec_altivec.c
95b418
 
95b418
 Intel x86
95b418
 M: Bruce Richardson <bruce.richardson@intel.com>
95b418
diff --git a/config/defconfig_ppc_64-power8-linuxapp-gcc b/config/defconfig_ppc_64-power8-linuxapp-gcc
95b418
index f953e61..5f160bc 100644
95b418
--- a/config/defconfig_ppc_64-power8-linuxapp-gcc
95b418
+++ b/config/defconfig_ppc_64-power8-linuxapp-gcc
95b418
@@ -49,7 +49,6 @@ CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=n
95b418
 # Note: Initially, all of the PMD drivers compilation are turned off on Power
95b418
 # Will turn on them only after the successful testing on Power
95b418
 CONFIG_RTE_LIBRTE_IXGBE_PMD=n
95b418
-CONFIG_RTE_LIBRTE_I40E_PMD=n
95b418
 CONFIG_RTE_LIBRTE_VIRTIO_PMD=y
95b418
 CONFIG_RTE_LIBRTE_VMXNET3_PMD=n
95b418
 CONFIG_RTE_LIBRTE_PMD_BOND=n
95b418
diff --git a/doc/guides/nics/features/i40e.ini b/doc/guides/nics/features/i40e.ini
95b418
index 0d143bc..36ac337 100644
95b418
--- a/doc/guides/nics/features/i40e.ini
95b418
+++ b/doc/guides/nics/features/i40e.ini
95b418
@@ -46,3 +46,4 @@ Linux VFIO           = Y
95b418
 x86-32               = Y
95b418
 x86-64               = Y
95b418
 ARMv8                = Y
95b418
+Power8               = Y
95b418
diff --git a/doc/guides/nics/features/i40e_vec.ini b/doc/guides/nics/features/i40e_vec.ini
95b418
index edd6b71..5ec4088 100644
95b418
--- a/doc/guides/nics/features/i40e_vec.ini
95b418
+++ b/doc/guides/nics/features/i40e_vec.ini
95b418
@@ -38,3 +38,4 @@ Linux VFIO           = Y
95b418
 x86-32               = Y
95b418
 x86-64               = Y
95b418
 ARMv8                = Y
95b418
+Power8               = Y
95b418
diff --git a/doc/guides/rel_notes/release_16_11.rst b/doc/guides/rel_notes/release_16_11.rst
95b418
index 8c9ec65..6186337 100644
95b418
--- a/doc/guides/rel_notes/release_16_11.rst
95b418
+++ b/doc/guides/rel_notes/release_16_11.rst
95b418
@@ -155,6 +155,9 @@ New Features
95b418
   The GCC 4.9 ``-march`` option supports the Intel processor code names.
95b418
   The config option ``RTE_MACHINE`` can be used to pass code names to the compiler via the ``-march`` flag.
95b418
 
95b418
+* **Added powerpc support for i40e and its vector PMD .**
95b418
+
95b418
+  i40e PMD and its vector PMD enabled by default in powerpc.
95b418
 
95b418
 Resolved Issues
95b418
 ---------------
95b418
diff --git a/drivers/net/i40e/Makefile b/drivers/net/i40e/Makefile
95b418
index 13085fb..9c9a867 100644
95b418
--- a/drivers/net/i40e/Makefile
95b418
+++ b/drivers/net/i40e/Makefile
95b418
@@ -99,6 +99,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_I40E_PMD) += i40e_ethdev.c
95b418
 SRCS-$(CONFIG_RTE_LIBRTE_I40E_PMD) += i40e_rxtx.c
95b418
 ifeq ($(CONFIG_RTE_ARCH_ARM64),y)
95b418
 SRCS-$(CONFIG_RTE_LIBRTE_I40E_INC_VECTOR) += i40e_rxtx_vec_neon.c
95b418
+else ifeq ($(CONFIG_RTE_ARCH_PPC_64),y)
95b418
+SRCS-$(CONFIG_RTE_LIBRTE_I40E_INC_VECTOR) += i40e_rxtx_vec_altivec.c
95b418
 else
95b418
 SRCS-$(CONFIG_RTE_LIBRTE_I40E_INC_VECTOR) += i40e_rxtx_vec_sse.c
95b418
 endif
95b418
diff --git a/drivers/net/i40e/i40e_rxtx_vec_altivec.c b/drivers/net/i40e/i40e_rxtx_vec_altivec.c
95b418
new file mode 100644
95b418
index 0000000..40d1929
95b418
--- /dev/null
95b418
+++ b/drivers/net/i40e/i40e_rxtx_vec_altivec.c
95b418
@@ -0,0 +1,654 @@
95b418
+/*-
95b418
+ *   BSD LICENSE
95b418
+ *
95b418
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
95b418
+ *   Copyright(c) 2017 IBM Corporation.
95b418
+ *   All rights reserved.
95b418
+ *
95b418
+ *   Redistribution and use in source and binary forms, with or without
95b418
+ *   modification, are permitted provided that the following conditions
95b418
+ *   are met:
95b418
+ *
95b418
+ *     * Redistributions of source code must retain the above copyright
95b418
+ *       notice, this list of conditions and the following disclaimer.
95b418
+ *     * Redistributions in binary form must reproduce the above copyright
95b418
+ *       notice, this list of conditions and the following disclaimer in
95b418
+ *       the documentation and/or other materials provided with the
95b418
+ *       distribution.
95b418
+ *     * Neither the name of Intel Corporation nor the names of its
95b418
+ *       contributors may be used to endorse or promote products derived
95b418
+ *       from this software without specific prior written permission.
95b418
+ *
95b418
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
95b418
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
95b418
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
95b418
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
95b418
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
95b418
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
95b418
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
95b418
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
95b418
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
95b418
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
95b418
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
95b418
+ */
95b418
+
95b418
+#include <stdint.h>
95b418
+#include <rte_ethdev.h>
95b418
+#include <rte_malloc.h>
95b418
+
95b418
+#include "base/i40e_prototype.h"
95b418
+#include "base/i40e_type.h"
95b418
+#include "i40e_ethdev.h"
95b418
+#include "i40e_rxtx.h"
95b418
+#include "i40e_rxtx_vec_common.h"
95b418
+
95b418
+#include <altivec.h>
95b418
+
95b418
+#pragma GCC diagnostic ignored "-Wcast-qual"
95b418
+
95b418
+static inline void
95b418
+i40e_rxq_rearm(struct i40e_rx_queue *rxq)
95b418
+{
95b418
+	int i;
95b418
+	uint16_t rx_id;
95b418
+	volatile union i40e_rx_desc *rxdp;
95b418
+
95b418
+	struct i40e_rx_entry *rxep = &rxq->sw_ring[rxq->rxrearm_start];
95b418
+	struct rte_mbuf *mb0, *mb1;
95b418
+
95b418
+	vector unsigned long hdr_room = (vector unsigned long){
95b418
+						RTE_PKTMBUF_HEADROOM,
95b418
+						RTE_PKTMBUF_HEADROOM};
95b418
+	vector unsigned long dma_addr0, dma_addr1;
95b418
+
95b418
+	rxdp = rxq->rx_ring + rxq->rxrearm_start;
95b418
+
95b418
+	/* Pull 'n' more MBUFs into the software ring */
95b418
+	if (rte_mempool_get_bulk(rxq->mp,
95b418
+				 (void *)rxep,
95b418
+				 RTE_I40E_RXQ_REARM_THRESH) < 0) {
95b418
+		if (rxq->rxrearm_nb + RTE_I40E_RXQ_REARM_THRESH >=
95b418
+		    rxq->nb_rx_desc) {
95b418
+			dma_addr0 = (vector unsigned long){};
95b418
+			for (i = 0; i < RTE_I40E_DESCS_PER_LOOP; i++) {
95b418
+				rxep[i].mbuf = &rxq->fake_mbuf;
95b418
+				vec_st(dma_addr0, 0,
95b418
+				       (vector unsigned long *)&rxdp[i].read);
95b418
+			}
95b418
+		}
95b418
+		rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
95b418
+			RTE_I40E_RXQ_REARM_THRESH;
95b418
+		return;
95b418
+	}
95b418
+
95b418
+	/* Initialize the mbufs in vector, process 2 mbufs in one loop */
95b418
+	for (i = 0; i < RTE_I40E_RXQ_REARM_THRESH; i += 2, rxep += 2) {
95b418
+		vector unsigned long vaddr0, vaddr1;
95b418
+		uintptr_t p0, p1;
95b418
+
95b418
+		mb0 = rxep[0].mbuf;
95b418
+		mb1 = rxep[1].mbuf;
95b418
+
95b418
+		 /* Flush mbuf with pkt template.
95b418
+		  * Data to be rearmed is 6 bytes long.
95b418
+		  * Though, RX will overwrite ol_flags that are coming next
95b418
+		  * anyway. So overwrite whole 8 bytes with one load:
95b418
+		  * 6 bytes of rearm_data plus first 2 bytes of ol_flags.
95b418
+		  */
95b418
+		p0 = (uintptr_t)&mb0->rearm_data;
95b418
+		*(uint64_t *)p0 = rxq->mbuf_initializer;
95b418
+		p1 = (uintptr_t)&mb1->rearm_data;
95b418
+		*(uint64_t *)p1 = rxq->mbuf_initializer;
95b418
+
95b418
+		/* load buf_addr(lo 64bit) and buf_physaddr(hi 64bit) */
95b418
+		vaddr0 = vec_ld(0, (vector unsigned long *)&mb0->buf_addr);
95b418
+		vaddr1 = vec_ld(0, (vector unsigned long *)&mb1->buf_addr);
95b418
+
95b418
+		/* convert pa to dma_addr hdr/data */
95b418
+		dma_addr0 = vec_mergel(vaddr0, vaddr0);
95b418
+		dma_addr1 = vec_mergel(vaddr1, vaddr1);
95b418
+
95b418
+		/* add headroom to pa values */
95b418
+		dma_addr0 = vec_add(dma_addr0, hdr_room);
95b418
+		dma_addr1 = vec_add(dma_addr1, hdr_room);
95b418
+
95b418
+		/* flush desc with pa dma_addr */
95b418
+		vec_st(dma_addr0, 0, (vector unsigned long *)&rxdp++->read);
95b418
+		vec_st(dma_addr1, 0, (vector unsigned long *)&rxdp++->read);
95b418
+	}
95b418
+
95b418
+	rxq->rxrearm_start += RTE_I40E_RXQ_REARM_THRESH;
95b418
+	if (rxq->rxrearm_start >= rxq->nb_rx_desc)
95b418
+		rxq->rxrearm_start = 0;
95b418
+
95b418
+	rxq->rxrearm_nb -= RTE_I40E_RXQ_REARM_THRESH;
95b418
+
95b418
+	rx_id = (uint16_t)((rxq->rxrearm_start == 0) ?
95b418
+			     (rxq->nb_rx_desc - 1) : (rxq->rxrearm_start - 1));
95b418
+
95b418
+	/* Update the tail pointer on the NIC */
95b418
+	I40E_PCI_REG_WRITE(rxq->qrx_tail, rx_id);
95b418
+}
95b418
+
95b418
+/* Handling the offload flags (olflags) field takes computation
95b418
+ * time when receiving packets. Therefore we provide a flag to disable
95b418
+ * the processing of the olflags field when they are not needed. This
95b418
+ * gives improved performance, at the cost of losing the offload info
95b418
+ * in the received packet
95b418
+ */
95b418
+#ifdef RTE_LIBRTE_I40E_RX_OLFLAGS_ENABLE
95b418
+
95b418
+static inline void
95b418
+desc_to_olflags_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts)
95b418
+{
95b418
+	vector unsigned int vlan0, vlan1, rss, l3_l4e;
95b418
+
95b418
+	/* mask everything except RSS, flow director and VLAN flags
95b418
+	 * bit2 is for VLAN tag, bit11 for flow director indication
95b418
+	 * bit13:12 for RSS indication.
95b418
+	 */
95b418
+	const vector unsigned int rss_vlan_msk = (vector unsigned int){
95b418
+			(int32_t)0x1c03804, (int32_t)0x1c03804,
95b418
+			(int32_t)0x1c03804, (int32_t)0x1c03804};
95b418
+
95b418
+	/* map rss and vlan type to rss hash and vlan flag */
95b418
+	const vector unsigned char vlan_flags = (vector unsigned char){
95b418
+			0, 0, 0, 0,
95b418
+			PKT_RX_VLAN_PKT | PKT_RX_VLAN_STRIPPED, 0, 0, 0,
95b418
+			0, 0, 0, 0,
95b418
+			0, 0, 0, 0};
95b418
+
95b418
+	const vector unsigned char rss_flags = (vector unsigned char){
95b418
+			0, PKT_RX_FDIR, 0, 0,
95b418
+			0, 0, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH | PKT_RX_FDIR,
95b418
+			0, 0, 0, 0,
95b418
+			0, 0, 0, 0};
95b418
+
95b418
+	const vector unsigned char l3_l4e_flags = (vector unsigned char){
95b418
+			0,
95b418
+			PKT_RX_IP_CKSUM_BAD,
95b418
+			PKT_RX_L4_CKSUM_BAD,
95b418
+			PKT_RX_L4_CKSUM_BAD | PKT_RX_IP_CKSUM_BAD,
95b418
+			PKT_RX_EIP_CKSUM_BAD,
95b418
+			PKT_RX_EIP_CKSUM_BAD | PKT_RX_IP_CKSUM_BAD,
95b418
+			PKT_RX_EIP_CKSUM_BAD | PKT_RX_L4_CKSUM_BAD,
95b418
+			PKT_RX_EIP_CKSUM_BAD | PKT_RX_L4_CKSUM_BAD
95b418
+					     | PKT_RX_IP_CKSUM_BAD,
95b418
+			0, 0, 0, 0, 0, 0, 0, 0};
95b418
+
95b418
+	vlan0 = (vector unsigned int)vec_mergel(descs[0], descs[1]);
95b418
+	vlan1 = (vector unsigned int)vec_mergel(descs[2], descs[3]);
95b418
+	vlan0 = (vector unsigned int)vec_mergeh(vlan0, vlan1);
95b418
+
95b418
+	vlan1 = vec_and(vlan0, rss_vlan_msk);
95b418
+	vlan0 = (vector unsigned int)vec_perm(vlan_flags,
95b418
+					(vector unsigned char){},
95b418
+					*(vector unsigned char *)&vlan1);
95b418
+
95b418
+	rss = vec_sr(vlan1, (vector unsigned int){11, 11, 11, 11});
95b418
+	rss = (vector unsigned int)vec_perm(rss_flags, (vector unsigned char){},
95b418
+					*(vector unsigned char *)&rss;;
95b418
+
95b418
+	l3_l4e = vec_sr(vlan1, (vector unsigned int){22, 22, 22, 22});
95b418
+	l3_l4e = (vector unsigned int)vec_perm(l3_l4e_flags,
95b418
+					(vector unsigned char){},
95b418
+					*(vector unsigned char *)&l3_l4e);
95b418
+
95b418
+	vlan0 = vec_or(vlan0, rss);
95b418
+	vlan0 = vec_or(vlan0, l3_l4e);
95b418
+
95b418
+	rx_pkts[0]->ol_flags = (uint64_t)vlan0[2];
95b418
+	rx_pkts[1]->ol_flags = (uint64_t)vlan0[3];
95b418
+	rx_pkts[2]->ol_flags = (uint64_t)vlan0[0];
95b418
+	rx_pkts[3]->ol_flags = (uint64_t)vlan0[1];
95b418
+}
95b418
+#else
95b418
+#define desc_to_olflags_v(desc, rx_pkts) do {} while (0)
95b418
+#endif
95b418
+
95b418
+#define PKTLEN_SHIFT     10
95b418
+
95b418
+static inline void
95b418
+desc_to_ptype_v(vector unsigned long descs[4], struct rte_mbuf **rx_pkts)
95b418
+{
95b418
+	vector unsigned long ptype0 = vec_mergel(descs[0], descs[1]);
95b418
+	vector unsigned long ptype1 = vec_mergel(descs[2], descs[3]);
95b418
+
95b418
+	ptype0 = vec_sr(ptype0, (vector unsigned long){30, 30});
95b418
+	ptype1 = vec_sr(ptype1, (vector unsigned long){30, 30});
95b418
+
95b418
+	rx_pkts[0]->packet_type = i40e_rxd_pkt_type_mapping(
95b418
+					(*(vector unsigned char *)&ptype0)[0]);
95b418
+	rx_pkts[1]->packet_type = i40e_rxd_pkt_type_mapping(
95b418
+					(*(vector unsigned char *)&ptype0)[8]);
95b418
+	rx_pkts[2]->packet_type = i40e_rxd_pkt_type_mapping(
95b418
+					(*(vector unsigned char *)&ptype1)[0]);
95b418
+	rx_pkts[3]->packet_type = i40e_rxd_pkt_type_mapping(
95b418
+					(*(vector unsigned char *)&ptype1)[8]);
95b418
+}
95b418
+
95b418
+ /* Notice:
95b418
+  * - nb_pkts < RTE_I40E_DESCS_PER_LOOP, just return no packet
95b418
+  * - nb_pkts > RTE_I40E_VPMD_RX_BURST, only scan RTE_I40E_VPMD_RX_BURST
95b418
+  *   numbers of DD bits
95b418
+  */
95b418
+static inline uint16_t
95b418
+_recv_raw_pkts_vec(struct i40e_rx_queue *rxq, struct rte_mbuf **rx_pkts,
95b418
+		   uint16_t nb_pkts, uint8_t *split_packet)
95b418
+{
95b418
+	volatile union i40e_rx_desc *rxdp;
95b418
+	struct i40e_rx_entry *sw_ring;
95b418
+	uint16_t nb_pkts_recd;
95b418
+	int pos;
95b418
+	uint64_t var;
95b418
+	vector unsigned char shuf_msk;
95b418
+
95b418
+	vector unsigned short crc_adjust = (vector unsigned short){
95b418
+		0, 0,         /* ignore pkt_type field */
95b418
+		rxq->crc_len, /* sub crc on pkt_len */
95b418
+		0,            /* ignore high-16bits of pkt_len */
95b418
+		rxq->crc_len, /* sub crc on data_len */
95b418
+		0, 0, 0       /* ignore non-length fields */
95b418
+		};
95b418
+	vector unsigned long dd_check, eop_check;
95b418
+
95b418
+	/* nb_pkts shall be less equal than RTE_I40E_MAX_RX_BURST */
95b418
+	nb_pkts = RTE_MIN(nb_pkts, RTE_I40E_MAX_RX_BURST);
95b418
+
95b418
+	/* nb_pkts has to be floor-aligned to RTE_I40E_DESCS_PER_LOOP */
95b418
+	nb_pkts = RTE_ALIGN_FLOOR(nb_pkts, RTE_I40E_DESCS_PER_LOOP);
95b418
+
95b418
+	/* Just the act of getting into the function from the application is
95b418
+	 * going to cost about 7 cycles
95b418
+	 */
95b418
+	rxdp = rxq->rx_ring + rxq->rx_tail;
95b418
+
95b418
+	rte_prefetch0(rxdp);
95b418
+
95b418
+	/* See if we need to rearm the RX queue - gives the prefetch a bit
95b418
+	 * of time to act
95b418
+	 */
95b418
+	if (rxq->rxrearm_nb > RTE_I40E_RXQ_REARM_THRESH)
95b418
+		i40e_rxq_rearm(rxq);
95b418
+
95b418
+	/* Before we start moving massive data around, check to see if
95b418
+	 * there is actually a packet available
95b418
+	 */
95b418
+	if (!(rxdp->wb.qword1.status_error_len &
95b418
+			rte_cpu_to_le_32(1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
95b418
+		return 0;
95b418
+
95b418
+	/* 4 packets DD mask */
95b418
+	dd_check = (vector unsigned long){0x0000000100000001ULL,
95b418
+					  0x0000000100000001ULL};
95b418
+
95b418
+	/* 4 packets EOP mask */
95b418
+	eop_check = (vector unsigned long){0x0000000200000002ULL,
95b418
+					   0x0000000200000002ULL};
95b418
+
95b418
+	/* mask to shuffle from desc. to mbuf */
95b418
+	shuf_msk = (vector unsigned char){
95b418
+		0xFF, 0xFF,   /* pkt_type set as unknown */
95b418
+		0xFF, 0xFF,   /* pkt_type set as unknown */
95b418
+		14, 15,       /* octet 15~14, low 16 bits pkt_len */
95b418
+		0xFF, 0xFF,   /* skip high 16 bits pkt_len, zero out */
95b418
+		14, 15,       /* octet 15~14, 16 bits data_len */
95b418
+		2, 3,         /* octet 2~3, low 16 bits vlan_macip */
95b418
+		4, 5, 6, 7    /* octet 4~7, 32bits rss */
95b418
+		};
95b418
+
95b418
+	/* Cache is empty -> need to scan the buffer rings, but first move
95b418
+	 * the next 'n' mbufs into the cache
95b418
+	 */
95b418
+	sw_ring = &rxq->sw_ring[rxq->rx_tail];
95b418
+
95b418
+	/* A. load 4 packet in one loop
95b418
+	 * [A*. mask out 4 unused dirty field in desc]
95b418
+	 * B. copy 4 mbuf point from swring to rx_pkts
95b418
+	 * C. calc the number of DD bits among the 4 packets
95b418
+	 * [C*. extract the end-of-packet bit, if requested]
95b418
+	 * D. fill info. from desc to mbuf
95b418
+	 */
95b418
+
95b418
+	for (pos = 0, nb_pkts_recd = 0; pos < nb_pkts;
95b418
+			pos += RTE_I40E_DESCS_PER_LOOP,
95b418
+			rxdp += RTE_I40E_DESCS_PER_LOOP) {
95b418
+		vector unsigned long descs[RTE_I40E_DESCS_PER_LOOP];
95b418
+		vector unsigned char pkt_mb1, pkt_mb2, pkt_mb3, pkt_mb4;
95b418
+		vector unsigned short staterr, sterr_tmp1, sterr_tmp2;
95b418
+		vector unsigned long mbp1, mbp2; /* two mbuf pointer
95b418
+						  * in one XMM reg.
95b418
+						  */
95b418
+
95b418
+		/* B.1 load 1 mbuf point */
95b418
+		mbp1 = *(vector unsigned long *)&sw_ring[pos];
95b418
+		/* Read desc statuses backwards to avoid race condition */
95b418
+		/* A.1 load 4 pkts desc */
95b418
+		descs[3] = *(vector unsigned long *)(rxdp + 3);
95b418
+		rte_compiler_barrier();
95b418
+
95b418
+		/* B.2 copy 2 mbuf point into rx_pkts  */
95b418
+		*(vector unsigned long *)&rx_pkts[pos] = mbp1;
95b418
+
95b418
+		/* B.1 load 1 mbuf point */
95b418
+		mbp2 = *(vector unsigned long *)&sw_ring[pos + 2];
95b418
+
95b418
+		descs[2] = *(vector unsigned long *)(rxdp + 2);
95b418
+		rte_compiler_barrier();
95b418
+		/* B.1 load 2 mbuf point */
95b418
+		descs[1] = *(vector unsigned long *)(rxdp + 1);
95b418
+		rte_compiler_barrier();
95b418
+		descs[0] = *(vector unsigned long *)(rxdp);
95b418
+
95b418
+		/* B.2 copy 2 mbuf point into rx_pkts  */
95b418
+		*(vector unsigned long *)&rx_pkts[pos + 2] =  mbp2;
95b418
+
95b418
+		if (split_packet) {
95b418
+			rte_mbuf_prefetch_part2(rx_pkts[pos]);
95b418
+			rte_mbuf_prefetch_part2(rx_pkts[pos + 1]);
95b418
+			rte_mbuf_prefetch_part2(rx_pkts[pos + 2]);
95b418
+			rte_mbuf_prefetch_part2(rx_pkts[pos + 3]);
95b418
+		}
95b418
+
95b418
+		/* avoid compiler reorder optimization */
95b418
+		rte_compiler_barrier();
95b418
+
95b418
+		/* pkt 3,4 shift the pktlen field to be 16-bit aligned*/
95b418
+		const vector unsigned int len3 = vec_sl(
95b418
+			vec_ld(0, (vector unsigned int *)&descs[3]),
95b418
+			(vector unsigned int){0, 0, 0, PKTLEN_SHIFT});
95b418
+
95b418
+		const vector unsigned int len2 = vec_sl(
95b418
+			vec_ld(0, (vector unsigned int *)&descs[2]),
95b418
+			(vector unsigned int){0, 0, 0, PKTLEN_SHIFT});
95b418
+
95b418
+		/* merge the now-aligned packet length fields back in */
95b418
+		descs[3] = (vector unsigned long)len3;
95b418
+		descs[2] = (vector unsigned long)len2;
95b418
+
95b418
+		/* D.1 pkt 3,4 convert format from desc to pktmbuf */
95b418
+		pkt_mb4 = vec_perm((vector unsigned char)descs[3],
95b418
+				  (vector unsigned char){}, shuf_msk);
95b418
+		pkt_mb3 = vec_perm((vector unsigned char)descs[2],
95b418
+				  (vector unsigned char){}, shuf_msk);
95b418
+
95b418
+		/* C.1 4=>2 filter staterr info only */
95b418
+		sterr_tmp2 = vec_mergel((vector unsigned short)descs[3],
95b418
+					(vector unsigned short)descs[2]);
95b418
+		/* C.1 4=>2 filter staterr info only */
95b418
+		sterr_tmp1 = vec_mergel((vector unsigned short)descs[1],
95b418
+					(vector unsigned short)descs[0]);
95b418
+		/* D.2 pkt 3,4 set in_port/nb_seg and remove crc */
95b418
+		pkt_mb4 = (vector unsigned char)vec_sub(
95b418
+				(vector unsigned short)pkt_mb4, crc_adjust);
95b418
+		pkt_mb3 = (vector unsigned char)vec_sub(
95b418
+				(vector unsigned short)pkt_mb3, crc_adjust);
95b418
+
95b418
+		/* pkt 1,2 shift the pktlen field to be 16-bit aligned*/
95b418
+		const vector unsigned int len1 = vec_sl(
95b418
+			vec_ld(0, (vector unsigned int *)&descs[1]),
95b418
+			(vector unsigned int){0, 0, 0, PKTLEN_SHIFT});
95b418
+		const vector unsigned int len0 = vec_sl(
95b418
+			vec_ld(0, (vector unsigned int *)&descs[0]),
95b418
+			(vector unsigned int){0, 0, 0, PKTLEN_SHIFT});
95b418
+
95b418
+		/* merge the now-aligned packet length fields back in */
95b418
+		descs[1] = (vector unsigned long)len1;
95b418
+		descs[0] = (vector unsigned long)len0;
95b418
+
95b418
+		/* D.1 pkt 1,2 convert format from desc to pktmbuf */
95b418
+		pkt_mb2 = vec_perm((vector unsigned char)descs[1],
95b418
+				   (vector unsigned char){}, shuf_msk);
95b418
+		pkt_mb1 = vec_perm((vector unsigned char)descs[0],
95b418
+				   (vector unsigned char){}, shuf_msk);
95b418
+
95b418
+		/* C.2 get 4 pkts staterr value  */
95b418
+		staterr = (vector unsigned short)vec_mergeh(
95b418
+				sterr_tmp1, sterr_tmp2);
95b418
+
95b418
+		/* D.3 copy final 3,4 data to rx_pkts */
95b418
+		vec_st(pkt_mb4, 0,
95b418
+		 (vector unsigned char *)&rx_pkts[pos + 3]
95b418
+			->rx_descriptor_fields1
95b418
+		);
95b418
+		vec_st(pkt_mb3, 0,
95b418
+		 (vector unsigned char *)&rx_pkts[pos + 2]
95b418
+			->rx_descriptor_fields1
95b418
+		);
95b418
+
95b418
+		/* D.2 pkt 1,2 set in_port/nb_seg and remove crc */
95b418
+		pkt_mb2 = (vector unsigned char)vec_sub(
95b418
+				(vector unsigned short)pkt_mb2, crc_adjust);
95b418
+		pkt_mb1 = (vector unsigned char)vec_sub(
95b418
+				(vector unsigned short)pkt_mb1,	crc_adjust);
95b418
+
95b418
+		/* C* extract and record EOP bit */
95b418
+		if (split_packet) {
95b418
+			vector unsigned char eop_shuf_mask =
95b418
+				(vector unsigned char){
95b418
+					0xFF, 0xFF, 0xFF, 0xFF,
95b418
+					0xFF, 0xFF, 0xFF, 0xFF,
95b418
+					0xFF, 0xFF, 0xFF, 0xFF,
95b418
+					0x04, 0x0C, 0x00, 0x08
95b418
+				};
95b418
+
95b418
+			/* and with mask to extract bits, flipping 1-0 */
95b418
+			vector unsigned char eop_bits = vec_and(
95b418
+				(vector unsigned char)vec_nor(staterr, staterr),
95b418
+				(vector unsigned char)eop_check);
95b418
+			/* the staterr values are not in order, as the count
95b418
+			 * count of dd bits doesn't care. However, for end of
95b418
+			 * packet tracking, we do care, so shuffle. This also
95b418
+			 * compresses the 32-bit values to 8-bit
95b418
+			 */
95b418
+			eop_bits = vec_perm(eop_bits, (vector unsigned char){},
95b418
+					    eop_shuf_mask);
95b418
+			/* store the resulting 32-bit value */
95b418
+			*split_packet = (vec_ld(0,
95b418
+					 (vector unsigned int *)&eop_bits))[0];
95b418
+			split_packet += RTE_I40E_DESCS_PER_LOOP;
95b418
+
95b418
+			/* zero-out next pointers */
95b418
+			rx_pkts[pos]->next = NULL;
95b418
+			rx_pkts[pos + 1]->next = NULL;
95b418
+			rx_pkts[pos + 2]->next = NULL;
95b418
+			rx_pkts[pos + 3]->next = NULL;
95b418
+		}
95b418
+
95b418
+		/* C.3 calc available number of desc */
95b418
+		staterr = vec_and(staterr, (vector unsigned short)dd_check);
95b418
+
95b418
+		/* D.3 copy final 1,2 data to rx_pkts */
95b418
+		vec_st(pkt_mb2, 0,
95b418
+		 (vector unsigned char *)&rx_pkts[pos + 1]
95b418
+			->rx_descriptor_fields1
95b418
+		);
95b418
+		vec_st(pkt_mb1, 0,
95b418
+		 (vector unsigned char *)&rx_pkts[pos]->rx_descriptor_fields1
95b418
+		);
95b418
+		desc_to_ptype_v(descs, &rx_pkts[pos]);
95b418
+		desc_to_olflags_v(descs, &rx_pkts[pos]);
95b418
+
95b418
+		/* C.4 calc avaialbe number of desc */
95b418
+		var = __builtin_popcountll((vec_ld(0,
95b418
+			(vector unsigned long *)&staterr)[0]));
95b418
+		nb_pkts_recd += var;
95b418
+		if (likely(var != RTE_I40E_DESCS_PER_LOOP))
95b418
+			break;
95b418
+	}
95b418
+
95b418
+	/* Update our internal tail pointer */
95b418
+	rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_pkts_recd);
95b418
+	rxq->rx_tail = (uint16_t)(rxq->rx_tail & (rxq->nb_rx_desc - 1));
95b418
+	rxq->rxrearm_nb = (uint16_t)(rxq->rxrearm_nb + nb_pkts_recd);
95b418
+
95b418
+	return nb_pkts_recd;
95b418
+}
95b418
+
95b418
+ /* Notice:
95b418
+  * - nb_pkts < RTE_I40E_DESCS_PER_LOOP, just return no packet
95b418
+  * - nb_pkts > RTE_I40E_VPMD_RX_BURST, only scan RTE_I40E_VPMD_RX_BURST
95b418
+  *   numbers of DD bits
95b418
+  */
95b418
+uint16_t
95b418
+i40e_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
95b418
+		   uint16_t nb_pkts)
95b418
+{
95b418
+	return _recv_raw_pkts_vec(rx_queue, rx_pkts, nb_pkts, NULL);
95b418
+}
95b418
+
95b418
+ /* vPMD receive routine that reassembles scattered packets
95b418
+  * Notice:
95b418
+  * - nb_pkts < RTE_I40E_DESCS_PER_LOOP, just return no packet
95b418
+  * - nb_pkts > RTE_I40E_VPMD_RX_BURST, only scan RTE_I40E_VPMD_RX_BURST
95b418
+  *   numbers of DD bits
95b418
+  */
95b418
+uint16_t
95b418
+i40e_recv_scattered_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
95b418
+			     uint16_t nb_pkts)
95b418
+{
95b418
+	struct i40e_rx_queue *rxq = rx_queue;
95b418
+	uint8_t split_flags[RTE_I40E_VPMD_RX_BURST] = {0};
95b418
+
95b418
+	/* get some new buffers */
95b418
+	uint16_t nb_bufs = _recv_raw_pkts_vec(rxq, rx_pkts, nb_pkts,
95b418
+			split_flags);
95b418
+	if (nb_bufs == 0)
95b418
+		return 0;
95b418
+
95b418
+	/* happy day case, full burst + no packets to be joined */
95b418
+	const uint64_t *split_fl64 = (uint64_t *)split_flags;
95b418
+
95b418
+	if (rxq->pkt_first_seg == NULL &&
95b418
+	    split_fl64[0] == 0 && split_fl64[1] == 0 &&
95b418
+	    split_fl64[2] == 0 && split_fl64[3] == 0)
95b418
+		return nb_bufs;
95b418
+
95b418
+	/* reassemble any packets that need reassembly*/
95b418
+	unsigned int i = 0;
95b418
+
95b418
+	if (!rxq->pkt_first_seg) {
95b418
+		/* find the first split flag, and only reassemble then*/
95b418
+		while (i < nb_bufs && !split_flags[i])
95b418
+			i++;
95b418
+		if (i == nb_bufs)
95b418
+			return nb_bufs;
95b418
+	}
95b418
+	return i + reassemble_packets(rxq, &rx_pkts[i], nb_bufs - i,
95b418
+		&split_flags[i]);
95b418
+}
95b418
+
95b418
+static inline void
95b418
+vtx1(volatile struct i40e_tx_desc *txdp,
95b418
+	struct rte_mbuf *pkt, uint64_t flags)
95b418
+{
95b418
+	uint64_t high_qw = (I40E_TX_DESC_DTYPE_DATA |
95b418
+		((uint64_t)flags  << I40E_TXD_QW1_CMD_SHIFT) |
95b418
+		((uint64_t)pkt->data_len << I40E_TXD_QW1_TX_BUF_SZ_SHIFT));
95b418
+
95b418
+	vector unsigned long descriptor = (vector unsigned long){
95b418
+		pkt->buf_physaddr + pkt->data_off, high_qw};
95b418
+	*(vector unsigned long *)txdp = descriptor;
95b418
+}
95b418
+
95b418
+static inline void
95b418
+vtx(volatile struct i40e_tx_desc *txdp,
95b418
+	struct rte_mbuf **pkt, uint16_t nb_pkts,  uint64_t flags)
95b418
+{
95b418
+	int i;
95b418
+
95b418
+	for (i = 0; i < nb_pkts; ++i, ++txdp, ++pkt)
95b418
+		vtx1(txdp, *pkt, flags);
95b418
+}
95b418
+
95b418
+uint16_t
95b418
+i40e_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
95b418
+		   uint16_t nb_pkts)
95b418
+{
95b418
+	struct i40e_tx_queue *txq = (struct i40e_tx_queue *)tx_queue;
95b418
+	volatile struct i40e_tx_desc *txdp;
95b418
+	struct i40e_tx_entry *txep;
95b418
+	uint16_t n, nb_commit, tx_id;
95b418
+	uint64_t flags = I40E_TD_CMD;
95b418
+	uint64_t rs = I40E_TX_DESC_CMD_RS | I40E_TD_CMD;
95b418
+	int i;
95b418
+
95b418
+	/* cross rx_thresh boundary is not allowed */
95b418
+	nb_pkts = RTE_MIN(nb_pkts, txq->tx_rs_thresh);
95b418
+
95b418
+	if (txq->nb_tx_free < txq->tx_free_thresh)
95b418
+		i40e_tx_free_bufs(txq);
95b418
+
95b418
+	nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
95b418
+	nb_commit = nb_pkts;
95b418
+	if (unlikely(nb_pkts == 0))
95b418
+		return 0;
95b418
+
95b418
+	tx_id = txq->tx_tail;
95b418
+	txdp = &txq->tx_ring[tx_id];
95b418
+	txep = &txq->sw_ring[tx_id];
95b418
+
95b418
+	txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
95b418
+
95b418
+	n = (uint16_t)(txq->nb_tx_desc - tx_id);
95b418
+	if (nb_commit >= n) {
95b418
+		tx_backlog_entry(txep, tx_pkts, n);
95b418
+
95b418
+		for (i = 0; i < n - 1; ++i, ++tx_pkts, ++txdp)
95b418
+			vtx1(txdp, *tx_pkts, flags);
95b418
+
95b418
+		vtx1(txdp, *tx_pkts++, rs);
95b418
+
95b418
+		nb_commit = (uint16_t)(nb_commit - n);
95b418
+
95b418
+		tx_id = 0;
95b418
+		txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
95b418
+
95b418
+		/* avoid reach the end of ring */
95b418
+		txdp = &txq->tx_ring[tx_id];
95b418
+		txep = &txq->sw_ring[tx_id];
95b418
+	}
95b418
+
95b418
+	tx_backlog_entry(txep, tx_pkts, nb_commit);
95b418
+
95b418
+	vtx(txdp, tx_pkts, nb_commit, flags);
95b418
+
95b418
+	tx_id = (uint16_t)(tx_id + nb_commit);
95b418
+	if (tx_id > txq->tx_next_rs) {
95b418
+		txq->tx_ring[txq->tx_next_rs].cmd_type_offset_bsz |=
95b418
+			rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
95b418
+						I40E_TXD_QW1_CMD_SHIFT);
95b418
+		txq->tx_next_rs =
95b418
+			(uint16_t)(txq->tx_next_rs + txq->tx_rs_thresh);
95b418
+	}
95b418
+
95b418
+	txq->tx_tail = tx_id;
95b418
+
95b418
+	I40E_PCI_REG_WRITE(txq->qtx_tail, txq->tx_tail);
95b418
+
95b418
+	return nb_pkts;
95b418
+}
95b418
+
95b418
+void __attribute__((cold))
95b418
+i40e_rx_queue_release_mbufs_vec(struct i40e_rx_queue *rxq)
95b418
+{
95b418
+	_i40e_rx_queue_release_mbufs_vec(rxq);
95b418
+}
95b418
+
95b418
+int __attribute__((cold))
95b418
+i40e_rxq_vec_setup(struct i40e_rx_queue *rxq)
95b418
+{
95b418
+	return i40e_rxq_vec_setup_default(rxq);
95b418
+}
95b418
+
95b418
+int __attribute__((cold))
95b418
+i40e_txq_vec_setup(struct i40e_tx_queue __rte_unused * txq)
95b418
+{
95b418
+	return 0;
95b418
+}
95b418
+
95b418
+int __attribute__((cold))
95b418
+i40e_rx_vec_dev_conf_condition_check(struct rte_eth_dev *dev)
95b418
+{
95b418
+	return i40e_rx_vec_dev_conf_condition_check_default(dev);
95b418
+}
95b418
-- 
95b418
1.9.1
95b418