diff mbox series

[v2,4/6] linux-gen: dpdk: RX - process checksum validation offload flags

Message ID 1502870408-2658-5-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v2,1/6] linux-gen: pktio: initialize pktio configuration structure | expand

Commit Message

Github ODP bot Aug. 16, 2017, 8 a.m. UTC
From: Bogdan Pricope <bogdan.pricope@linaro.org>


Signed-off-by: Bogdan Pricope <bogdan.pricope@linaro.org>

---
/** Email created from pull request 124 (bogdanPricope:dpdk_hw_csum_pr)
 ** https://github.com/Linaro/odp/pull/124
 ** Patch: https://github.com/Linaro/odp/pull/124.patch
 ** Base sha: 90d4ce1b3b25ca18446131906007571cc0ed0191
 ** Merge commit sha: 223e557905dfa62704233e593e0a052a44fb3b4e
 **/
 platform/linux-generic/pktio/dpdk.c | 47 +++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
diff mbox series

Patch

diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c
index a5e1d4b5..af727ae0 100644
--- a/platform/linux-generic/pktio/dpdk.c
+++ b/platform/linux-generic/pktio/dpdk.c
@@ -301,6 +301,40 @@  static struct rte_mempool_ops ops_stack = {
 
 MEMPOOL_REGISTER_OPS(ops_stack);
 
+#define HAS_L4_PROTO(m, proto) ((m->packet_type & RTE_PTYPE_L4_MASK) == proto)
+
+static inline int pkt_set_ol_rx(odp_pktin_config_opt_t *pktin_cfg,
+				odp_packet_hdr_t *pkt_hdr,
+				struct rte_mbuf *mbuf)
+{
+	if (pktin_cfg->bit.ipv4_chksum &&
+	    (mbuf->packet_type & RTE_PTYPE_L3_IPV4) &&
+	    mbuf->ol_flags & PKT_RX_IP_CKSUM_BAD) {
+		if (pktin_cfg->bit.drop_ipv4_err)
+			return -1;
+
+		pkt_hdr->p.error_flags.ip_err = 1;
+	}
+
+	if (pktin_cfg->bit.udp_chksum &&
+	    HAS_L4_PROTO(mbuf, RTE_PTYPE_L4_UDP) &&
+	    mbuf->ol_flags & PKT_RX_L4_CKSUM_BAD) {
+		if (pktin_cfg->bit.drop_udp_err)
+			return -1;
+
+		pkt_hdr->p.error_flags.udp_err = 1;
+	} else if (pktin_cfg->bit.tcp_chksum &&
+		   HAS_L4_PROTO(mbuf, RTE_PTYPE_L4_TCP)  &&
+		   mbuf->ol_flags & PKT_RX_L4_CKSUM_BAD) {
+		if (pktin_cfg->bit.drop_tcp_err)
+			return -1;
+
+		pkt_hdr->p.error_flags.tcp_err = 1;
+	}
+
+	return 0;
+}
+
 static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry,
 			      odp_packet_t pkt_table[],
 			      struct rte_mbuf *mbuf_table[],
@@ -315,6 +349,7 @@  static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry,
 	int nb_pkts = 0;
 	int alloc_len, num;
 	odp_pool_t pool = pktio_entry->s.pkt_dpdk.pool;
+	odp_pktin_config_opt_t *pktin_cfg = &pktio_entry->s.config.pktin;
 
 	/* Allocate maximum sized packets */
 	alloc_len = pktio_entry->s.pkt_dpdk.data_room;
@@ -369,6 +404,12 @@  static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry,
 
 		packet_set_ts(pkt_hdr, ts);
 
+		if (pkt_set_ol_rx(pktin_cfg, pkt_hdr, mbuf)) {
+			odp_packet_free(pkt);
+			rte_pktmbuf_free(mbuf);
+			continue;
+		}
+
 		pkt_table[nb_pkts++] = pkt;
 
 		rte_pktmbuf_free(mbuf);
@@ -435,6 +476,7 @@  static inline int mbuf_to_pkt_zero(pktio_entry_t *pktio_entry,
 	int i;
 	int nb_pkts = 0;
 	odp_pool_t pool = pktio_entry->s.pkt_dpdk.pool;
+	odp_pktin_config_opt_t *pktin_cfg = &pktio_entry->s.config.pktin;
 
 	for (i = 0; i < mbuf_num; i++) {
 		odp_packet_hdr_t parsed_hdr;
@@ -480,6 +522,11 @@  static inline int mbuf_to_pkt_zero(pktio_entry_t *pktio_entry,
 
 		packet_set_ts(pkt_hdr, ts);
 
+		if (pkt_set_ol_rx(pktin_cfg, pkt_hdr, mbuf)) {
+			rte_pktmbuf_free(mbuf);
+			continue;
+		}
+
 		pkt_table[nb_pkts++] = pkt;
 	}