From patchwork Mon Aug 14 11:00:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 109986 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp4179941qge; Mon, 14 Aug 2017 04:03:49 -0700 (PDT) X-Received: by 10.55.59.193 with SMTP id i184mr8211838qka.214.1502708629635; Mon, 14 Aug 2017 04:03:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502708629; cv=none; d=google.com; s=arc-20160816; b=UMmhqzjeU0x+FEO9Xpq0MeyYTNXxplglBGM6sze117F6v6V4MihCbnN0eJmyC5o4tr fX4kGtxw2BDiRLKg/CO+mHGFWLoUNn9uGPsyn5OoxYagZXvZXudfFKQ/qK0LFrJcjdXB tt1ESFWA2q2YcTdfUPkDkmM6mUWy731iKns4QlBiKdZ50XD5/rtMAZCtc/bATl5Edhj3 kj6KRKAV4k+Z6PtSCOtBdANMVPgs51pRRbIQyoTW6Wc1kBHFR1wTQ0oIj8uMBLMZaQpe 1hXW8eeVDLq6fYUqH7VGVWjgaZUhYYmnQjUpQSm3XdcqEWdysJcItzmGqi+BweF0+NJj hkAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=R7EkdrFqQ3P5+a6IxU5qi1z/+kd8HxSb5Inv/AIi+1w=; b=weL88KwZ0yU/vGJ3FK2xePUZB0gADfpUTaaLh/YRHzvek8Vuo/wUuqE1kGr+6lSKt2 gIuIcXJCgH712AcPcLaxxqM8/CLxjP+mglCZuxuOixLSDoVDdaPXha0UvQgL6jewVCPM P47OFQEoGDPl22n4GfTM4cwr/jbhRvw4RgTHlHI9ef8/2U7/AbcD9UR+IF2+eW2vqNAW 6ozpl1sQrfYIpZbNHwYoE7c0FlqJwQ7LWKgkhG5EHHsF7Ft11upJAOYMP9dEQt6ivFLY NEgW9XmGkXvcDpNRqOUcdJKqJtK3EIt08RHy53r6AxWnuTac/RYLR5bx34DaPOUBr4H9 nUsQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k64si4675862qkf.265.2017.08.14.04.03.49; Mon, 14 Aug 2017 04:03:49 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 358E565C3F; Mon, 14 Aug 2017 11:03:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 915C265C47; Mon, 14 Aug 2017 11:00:46 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3A5F665C33; Mon, 14 Aug 2017 11:00:34 +0000 (UTC) Received: from forward105p.mail.yandex.net (forward105p.mail.yandex.net [77.88.28.108]) by lists.linaro.org (Postfix) with ESMTPS id 38A4C65C2E for ; Mon, 14 Aug 2017 11:00:30 +0000 (UTC) Received: from mxback4g.mail.yandex.net (mxback4g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:165]) by forward105p.mail.yandex.net (Yandex) with ESMTP id 43A354080C9D for ; Mon, 14 Aug 2017 14:00:28 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback4g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id dMEwdMA2li-0RbWAlp9; Mon, 14 Aug 2017 14:00:28 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id n8iAsiDcdV-0QVOkAme; Mon, 14 Aug 2017 14:00:26 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Mon, 14 Aug 2017 14:00:07 +0300 Message-Id: <1502708408-10504-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1502708408-10504-1-git-send-email-odpbot@yandex.ru> References: <1502708408-10504-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 124 Subject: [lng-odp] [PATCH v1 5/6] dpdk: TX - set checksum calculation offload flags X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Bogdan Pricope Signed-off-by: Bogdan Pricope --- /** 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: de5ffd818401be95fd7eb3398670d1b92d27d2de **/ platform/linux-generic/pktio/dpdk.c | 109 ++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index af727ae0..1172e9e2 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -30,6 +30,10 @@ #include #include #include +#include +#include +#include +#include #include #if ODP_DPDK_ZERO_COPY @@ -426,6 +430,96 @@ static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, return (i > 0 ? i : -1); } +static inline int packet_parse(void *l3_hdr, uint8_t *l3_proto_v4, + uint8_t *l4_proto) +{ + uint8_t l3_proto_ver = _ODP_IPV4HDR_VER(*(uint8_t *)l3_hdr); + + if (l3_proto_ver == _ODP_IPV4) { + struct ipv4_hdr *ip = (struct ipv4_hdr *)l3_hdr; + + *l3_proto_v4 = 1; + if (!rte_ipv4_frag_pkt_is_fragmented(ip)) + *l4_proto = ip->next_proto_id; + else + *l4_proto = 0; + + return 0; + } else if (l3_proto_ver == _ODP_IPV6) { + struct ipv6_hdr *ipv6 = (struct ipv6_hdr *)l3_hdr; + + *l3_proto_v4 = 0; + *l4_proto = ipv6->proto; + return 0; + } + + return -1; +} + +static inline uint16_t phdr_csum(int ipv4, void *l3_hdr, + uint64_t ol_flags) +{ + if (ipv4) + return rte_ipv4_phdr_cksum(l3_hdr, ol_flags); + else /*ipv6*/ + return rte_ipv6_phdr_cksum(l3_hdr, ol_flags); +} + +static inline int pkt_set_ol_tx(odp_pktout_config_opt_t *pktout_cfg, + odp_packet_hdr_t *pkt_hdr, + struct rte_mbuf *mbuf, + char *mbuf_data) +{ + void *l3_hdr, *l4_hdr; + uint8_t l3_proto_v4, l4_proto; + odp_bool_t ipv4_chksum_pkt, udp_chksum_pkt, tcp_chksum_pkt; + packet_parser_t *pkt_p = &pkt_hdr->p; + + l3_hdr = (void *)(mbuf_data + pkt_p->l3_offset); + + if (packet_parse(l3_hdr, &l3_proto_v4, &l4_proto)) + return 0; + + ipv4_chksum_pkt = pktout_cfg->bit.ipv4_chksum && l3_proto_v4; + udp_chksum_pkt = pktout_cfg->bit.udp_chksum && + (l4_proto == _ODP_IPPROTO_UDP); + tcp_chksum_pkt = pktout_cfg->bit.tcp_chksum && + (l4_proto == _ODP_IPPROTO_TCP); + + if (!ipv4_chksum_pkt && !udp_chksum_pkt && !tcp_chksum_pkt) + return 0; + + mbuf->l2_len = pkt_p->l3_offset - pkt_p->l2_offset; + mbuf->l3_len = pkt_p->l4_offset - pkt_p->l3_offset; + + if (l3_proto_v4) + mbuf->ol_flags = PKT_TX_IPV4; + else + mbuf->ol_flags = PKT_TX_IPV6; + + if (ipv4_chksum_pkt) { + mbuf->ol_flags |= PKT_TX_IP_CKSUM; + + ((struct ipv4_hdr *)l3_hdr)->hdr_checksum = 0; + } + + l4_hdr = (void *)(mbuf_data + pkt_p->l4_offset); + + if (udp_chksum_pkt) { + mbuf->ol_flags |= PKT_TX_UDP_CKSUM; + + ((struct udp_hdr *)l4_hdr)->dgram_cksum = + phdr_csum(l3_proto_v4, l3_hdr, mbuf->ol_flags); + } else if (tcp_chksum_pkt) { + mbuf->ol_flags |= PKT_TX_TCP_CKSUM; + + ((struct tcp_hdr *)l4_hdr)->cksum = + phdr_csum(l3_proto_v4, l3_hdr, mbuf->ol_flags); + } + + return 0; +} + static inline int pkt_to_mbuf(pktio_entry_t *pktio_entry, struct rte_mbuf *mbuf_table[], const odp_packet_t pkt_table[], uint16_t num) @@ -434,6 +528,7 @@ static inline int pkt_to_mbuf(pktio_entry_t *pktio_entry, int i, j; char *data; uint16_t pkt_len; + odp_pktout_config_opt_t *pktout_cfg = &pktio_entry->s.config.pktout; if (odp_unlikely((rte_pktmbuf_alloc_bulk(pkt_dpdk->pkt_pool, mbuf_table, num)))) { @@ -453,6 +548,11 @@ static inline int pkt_to_mbuf(pktio_entry_t *pktio_entry, data = rte_pktmbuf_append(mbuf_table[i], pkt_len); odp_packet_copy_to_mem(pkt_table[i], 0, pkt_len, data); + + if (pktout_cfg->all_bits) + pkt_set_ol_tx(pktout_cfg, + odp_packet_hdr(pkt_table[i]), + mbuf_table[i], data); } return i; @@ -539,6 +639,7 @@ static inline int pkt_to_mbuf_zero(pktio_entry_t *pktio_entry, uint16_t *copy_count) { pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + odp_pktout_config_opt_t *pktout_cfg = &pktio_entry->s.config.pktout; int i; *copy_count = 0; @@ -555,6 +656,10 @@ static inline int pkt_to_mbuf_zero(pktio_entry_t *pktio_entry, if (odp_likely(pkt_hdr->buf_hdr.segcount == 1 && pkt_hdr->extra_type == PKT_EXTRA_TYPE_DPDK)) { mbuf_update(mbuf, pkt_hdr, pkt_len); + + if (pktout_cfg->all_bits) + pkt_set_ol_tx(pktout_cfg, pkt_hdr, + mbuf, odp_packet_data(pkt)); } else { pool_t *pool_entry = pkt_hdr->buf_hdr.pool_ptr; @@ -570,6 +675,10 @@ static inline int pkt_to_mbuf_zero(pktio_entry_t *pktio_entry, mbuf_init(pkt_dpdk->pkt_pool, mbuf, pkt_hdr); mbuf_update(mbuf, pkt_hdr, pkt_len); + if (pktout_cfg->all_bits) + pkt_set_ol_tx(pktout_cfg, pkt_hdr, + mbuf, + odp_packet_data(pkt)); } } mbuf_table[i] = mbuf;