diff mbox series

[v3,3/5] linux-gen: dpdk: RX - process checksum validation offload flags

Message ID 1503388810-6999-4-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v3,1/5] linux-gen: dpdk: retrieve offload capabilities | expand

Commit Message

Github ODP bot Aug. 22, 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: aecb3c7a442b426761f1e6f43308a1e9ea709ef3
 ** Merge commit sha: 23658e7f5acf9d3621ec7a8f617db98a26ee1bda
 **/
 platform/linux-generic/pktio/dpdk.c | 59 +++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
diff mbox series

Patch

diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c
index 693c0c97..6dfb8c7a 100644
--- a/platform/linux-generic/pktio/dpdk.c
+++ b/platform/linux-generic/pktio/dpdk.c
@@ -301,6 +301,48 @@  static struct rte_mempool_ops ops_stack = {
 
 MEMPOOL_REGISTER_OPS(ops_stack);
 
+#define HAS_IP4_PROTO(m, proto) ((m->packet_type & RTE_PTYPE_L3_MASK) == proto)
+#define HAS_IP4_PROTOS(m) (HAS_IP4_PROTO(m, RTE_PTYPE_L3_IPV4) ||\
+			   HAS_IP4_PROTO(m, RTE_PTYPE_L3_IPV4_EXT) ||\
+			   HAS_IP4_PROTO(m, RTE_PTYPE_L3_IPV4_EXT_UNKNOWN))
+#define HAS_IP4_CSUM_FLAG(m, f) ((m->ol_flags & PKT_RX_IP_CKSUM_MASK) == f)
+#define HAS_L4_PROTO(m, proto) ((m->packet_type & RTE_PTYPE_L4_MASK) == proto)
+#define HAS_L4_CSUM_FLAG(m, f) ((m->ol_flags & PKT_RX_L4_CKSUM_MASK) == f)
+
+#define PKTIN_CSUM_BITS 0x1C
+
+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 &&
+	    HAS_IP4_PROTOS(mbuf) &&
+	    HAS_IP4_CSUM_FLAG(mbuf, 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) &&
+	    HAS_L4_CSUM_FLAG(mbuf, 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)  &&
+		   HAS_L4_CSUM_FLAG(mbuf, 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 +357,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 +412,14 @@  static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry,
 
 		packet_set_ts(pkt_hdr, ts);
 
+		if (pktin_cfg->all_bits & PKTIN_CSUM_BITS) {
+			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 +486,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 +532,13 @@  static inline int mbuf_to_pkt_zero(pktio_entry_t *pktio_entry,
 
 		packet_set_ts(pkt_hdr, ts);
 
+		if (pktin_cfg->all_bits & PKTIN_CSUM_BITS) {
+			if (pkt_set_ol_rx(pktin_cfg, pkt_hdr, mbuf)) {
+				rte_pktmbuf_free(mbuf);
+				continue;
+			}
+		}
+
 		pkt_table[nb_pkts++] = pkt;
 	}