From patchwork Tue Sep 5 10:06:34 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: 111649 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp2630743qge; Tue, 5 Sep 2017 03:15:55 -0700 (PDT) X-Google-Smtp-Source: ADKCNb7WulMuHzCK1Uik6in0oHej0cVZbO/IXhyWElWdCI4FUyvKBN+/ijgF/WeTya9v/zmPGBIo X-Received: by 10.55.143.129 with SMTP id r123mr4618196qkd.9.1504606555018; Tue, 05 Sep 2017 03:15:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504606555; cv=none; d=google.com; s=arc-20160816; b=drsdxCma6ncbzaCrKkhhU9lrspvRx3Tm6SqDCpAz7MwS8MlZ0ckk3tdD2IS2p1yAWJ /IlbwcIegEiqpzGQJ7lmRl69bcWgBWl9THRXy8ZoOMdlzlYflgIPOzfUDo73vx42nb4j wQ4dmNkMQ8TUGHweExnx1T977bbHJPKHU9zATp+W3BAdrYXvCLl/XtmPdvocB47zVfum iejOT3lruHRWcyxn0KLhDFMYvztpdVnMJ/l4UYiynH/wCwnowGThdibB61P2NKxzkBpo KpUafbasFN9ZdAy44Es6rSIjhzJiLBA0mudPlGRwv1vCfP7uFAfyyETFmarMvc2ks0CG HgJQ== 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=i+2EgKsDfuDcAtd84lRirdg7fLufN+aZKbnfzZ1W76Y=; b=iRT6PXINyUffgDW/h6WfM7Ks25mY73cj4ZZDfZ7oMFUK9y/Or38V0obfUCR21061/5 BIHxzs0OO2qwuy04ifiwHiZCBv2EJpwTP87ebk7baRbLucHobyKVAqd/tyQVv1HetV8k 7wt6oJN3DDorbIehz8REX4T+MaGoi8P+fAD5BreBEZbZQ8Ev4R/RxELcexR9/RE/HoqX Vz5re0C3B3xK8KTM3MpN7YFWjpqjr1vNh7jmgF4/nmsgLWOcf4EqWpQK+TWd4F/5BJb4 FyrjfDOgcsEDbsP9iyL6qQF7Zjc8TYc9eEIK4iYdkuwqY3cY/4WWzuzopS0SlCRKN+0p sVDw== 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 n91si297947qtd.483.2017.09.05.03.15.54; Tue, 05 Sep 2017 03:15:55 -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 B371562C60; Tue, 5 Sep 2017 10:15:54 +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 0243F61BC6; Tue, 5 Sep 2017 10:09:16 +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 B94CF60D83; Tue, 5 Sep 2017 10:09:00 +0000 (UTC) Received: from forward103p.mail.yandex.net (forward103p.mail.yandex.net [77.88.28.106]) by lists.linaro.org (Postfix) with ESMTPS id 0FC8660D83 for ; Tue, 5 Sep 2017 10:06:44 +0000 (UTC) Received: from mxback5g.mail.yandex.net (mxback5g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:166]) by forward103p.mail.yandex.net (Yandex) with ESMTP id 1A52F218201D for ; Tue, 5 Sep 2017 13:06:43 +0300 (MSK) Received: from smtp3p.mail.yandex.net (smtp3p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:8]) by mxback5g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id s6OB9bQgoU-6g4CrrNc; Tue, 05 Sep 2017 13:06:43 +0300 Received: by smtp3p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id oPs3E3RFkM-6gOGI4AN; Tue, 05 Sep 2017 13:06:42 +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: Tue, 5 Sep 2017 13:06:34 +0300 Message-Id: <1504605995-28026-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1504605995-28026-1-git-send-email-odpbot@yandex.ru> References: <1504605995-28026-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 124 Subject: [lng-odp] [PATCH v4 4/5] 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: 7508c5ac906bb7cb1d339b4c5e924f3a18e504ca ** Merge commit sha: 086fe31f96e49f97f945702d0691f019245b959c **/ platform/linux-generic/pktio/dpdk.c | 108 ++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index 891adcd5..26ca0d6b 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -32,6 +32,10 @@ #include #include #include +#include +#include +#include +#include #include #if ODP_DPDK_ZERO_COPY @@ -434,6 +438,95 @@ static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, return (i > 0 ? i : -1); } +static inline int check_proto(void *l3_hdr, odp_bool_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(odp_bool_t 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 void 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 l4_proto; + odp_bool_t l3_proto_v4; + 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 (check_proto(l3_hdr, &l3_proto_v4, &l4_proto)) + return; + + 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; + + 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); + } +} + 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) @@ -442,6 +535,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)))) { @@ -461,6 +555,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; @@ -549,6 +648,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; @@ -565,6 +665,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; @@ -580,6 +684,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;