From patchwork Wed Aug 16 08: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: 110209 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp459559qge; Wed, 16 Aug 2017 01:03:09 -0700 (PDT) X-Received: by 10.200.39.206 with SMTP id x14mr1157559qtx.259.1502870589719; Wed, 16 Aug 2017 01:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502870589; cv=none; d=google.com; s=arc-20160816; b=sRhCpJPStOnNpO/yl+thwfVRjTJPZuLmdNWfB+8iMvT/vEhoobr0l/YRb20i7dvvwX PZzgzmI/FT4WXAzvl46fLo8OnFpl9TWVkMzJ/v2KX2DZY/WffVSKwbzVEq5/nm7KffTm ktK5nW+NTWR0blOZwqzc2PmPYLP5+nBmz6IWLQn0poz+9FjC4u3fQKIylKW5Ez5TYIy5 KgAisvVpyxVyONpDOeTd0/hMbvIfzB6NPvlnN2U8wsg2PLY+1A5D4EbmBJ2RYRWUrPrp BiCs2u4Mk482f921hTahFoLB67mTi/7QXp+xG+QN1UXmTtI0XAu4i+oVAmvLYTTkOtJH yvbw== 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=pROD6PZsALoCZsxSsO+XIHPaIUQrWiN9JSeuLCDw++s=; b=yYFkogyCuuhzIYOvFwCkZ3JvWXVcCBhSx1ZZd/RrDVAfTVRv3BLgQ20Njx7R9+50Ft ZfvOhCms7wxJ+z3zlLq8Ay9AFlHClvO0NCs7y2o9J5Gnvc60EF1gnnPkFw2UKmQc3VXM nhEEyIs7zrvz8uQhrFJ0iGznVXZdtyYJeyAIwqcJDQWzfQzuIDXWXu349LrpXOV4W9Ik k9b7IMClCBE194Adbtjolv8/fmHaZhY5HKNeFSYgoIIoRS450xbY25d7HFAociSA5f+8 VEWAflZd/+uDio+60AkDHjdKv6JmOJpgCbvKH/I/AfV5QugnttWeUPpCrt7liFeJF39T zpEg== 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 h186si264347qkc.200.2017.08.16.01.03.09; Wed, 16 Aug 2017 01:03:09 -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 65CDE644A4; Wed, 16 Aug 2017 08:03:09 +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, RCVD_IN_DNSWL_NONE,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 AD90D644AD; Wed, 16 Aug 2017 08:01:13 +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 BF80B608AA; Wed, 16 Aug 2017 08:00:53 +0000 (UTC) Received: from forward101p.mail.yandex.net (forward101p.mail.yandex.net [77.88.28.101]) by lists.linaro.org (Postfix) with ESMTPS id E7135644A6 for ; Wed, 16 Aug 2017 08:00:36 +0000 (UTC) Received: from mxback19j.mail.yandex.net (mxback19j.mail.yandex.net [IPv6:2a02:6b8:0:1619::95]) by forward101p.mail.yandex.net (Yandex) with ESMTP id E412B6A83EBA for ; Wed, 16 Aug 2017 11:00:35 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback19j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id SZQgoH5yut-0Zn8ZBDT; Wed, 16 Aug 2017 11:00:35 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id lI5XI3wvqw-0Z1GvZ4r; Wed, 16 Aug 2017 11:00:35 +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: Wed, 16 Aug 2017 11:00:07 +0300 Message-Id: <1502870408-2658-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1502870408-2658-1-git-send-email-odpbot@yandex.ru> References: <1502870408-2658-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 124 Subject: [lng-odp] [PATCH v2 5/6] linux-gen: 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: 223e557905dfa62704233e593e0a052a44fb3b4e **/ 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;