From patchwork Wed May 31 14:40:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Pricope X-Patchwork-Id: 100794 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp357147qge; Wed, 31 May 2017 07:43:39 -0700 (PDT) X-Received: by 10.237.59.225 with SMTP id s30mr30909584qte.192.1496241819120; Wed, 31 May 2017 07:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496241819; cv=none; d=google.com; s=arc-20160816; b=EZLMRxIuEbeCN1jHe33JAQyPYB+dJ0Ib26GZyhY6SbEVpAhrHHToPAix8Cw9kSsyEG MPljo+lhf43kpcMq8e6f/88kPO5iAYQJfNqW4ttufjDpQZQZQ2BiBk0ULzyORLwhKP7G CdCjvXf/1AShvKPSgYT6NapgkDwoLmsfwn9C4y/Gr1QMNNUHLypOIzmwizE0gBt+z5ji smaMnWAiLcnq8G3Gmlv8qnN4nokjwY9/6S7bQoguuNqbJPBkWt8C9SV5udPNthtMCKE8 Hnx1ywaAW0Td155bxqO/u+AVrNmy/milvtr23NqGwEHyJ7DeyaV3KaflRIz4PvOc2PPP 0iZA== 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:references:in-reply-to :message-id:date:to:from:delivered-to:arc-authentication-results; bh=YgYPFH6N1gOWR78RH2abOqMeHgdkxNexAk9BPS3IbFI=; b=RaB5GVAAtL5h8qvT5dbbkDjRXPnRzDWHpns0PDbA7lQXZIxI56Iw4WuVvNzTkVUDgA 2whmZ+GuyXJNfPWX7zxobZe9DJmVEJttVqJRKlDJM5UcaiVeF7GFjDx/4Q/IDch5wyWO hZlgDbMMQtl1Y5gJMFqQpz3C6YBixhXCVLgGbHQNb7/ub4FePxNKl76tf3AQuVUHxp56 7G6HH1NR6R5uQmaYl3Gw2TpAT9KVrsnXPmJB/9tNAljDCLjpGA3AY1KP0uRT4Nj1SVau TlFeYjXcGfaumbJoOwaQ2BKbi/kpwf1wuuDwJYi0Mr4imD5rrmvDyGRMk/IEkmfnAISI rY0A== 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id j16si16470729qtj.215.2017.05.31.07.43.38; Wed, 31 May 2017 07:43:39 -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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C2CBE6069C; Wed, 31 May 2017 14:43:38 +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.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, 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 923E260718; Wed, 31 May 2017 14:41:53 +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 9D10660CDC; Wed, 31 May 2017 14:41:48 +0000 (UTC) Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by lists.linaro.org (Postfix) with ESMTPS id DCB7160690 for ; Wed, 31 May 2017 14:41:22 +0000 (UTC) Received: by mail-wm0-f51.google.com with SMTP id e127so23688748wmg.1 for ; Wed, 31 May 2017 07:41:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YgYPFH6N1gOWR78RH2abOqMeHgdkxNexAk9BPS3IbFI=; b=lUqhFPDeS1eDunL6JZnTi/GdOB+lGRGdvFrgh4S83Df+qAD1X9EirMRX5PysnrhXrv I18rxfOwk4FktiyLaBfD3wsdQqLLll/M7dqzXb5rMvoiEtATET/RFoztDiUx8RGb2Fov /Pc3ZcUWWd0xa2Rn//hhRIuyCu08a8w7BGS6sS51qg/IXQFNoyok5Sf4UDIwIgI70Q+R i25CA8QERRsskP/WfxU6IL3K7p8Ty1If+61kX8vw+GMyc7Nl8Nz+bzRTxGwFhnpHkjHc btvUxadORwnELUt4naIk2EHq6C52XNQajej4dr+/jnKQurctNiLymuBjowG3RIQqjZ5R GAiw== X-Gm-Message-State: AODbwcCDBFAIsICAKxtLh9qBc/uKWIuBkcqB4t0OllDE5azWJHmBWvxH maKwxJaukH4LWqrIJq/gVVfP X-Received: by 10.223.135.248 with SMTP id c53mr4939272wrc.109.1496241681784; Wed, 31 May 2017 07:41:21 -0700 (PDT) Received: from netbricks-team.enea.se ([193.202.22.66]) by smtp.gmail.com with ESMTPSA id e23sm22483032wre.54.2017.05.31.07.41.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 May 2017 07:41:21 -0700 (PDT) From: Bogdan Pricope To: lng-odp@lists.linaro.org Date: Wed, 31 May 2017 17:40:59 +0300 Message-Id: <1496241660-27492-6-git-send-email-bogdan.pricope@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1496241660-27492-1-git-send-email-bogdan.pricope@linaro.org> References: <1496241660-27492-1-git-send-email-bogdan.pricope@linaro.org> Subject: [lng-odp] [PATCH 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" Signed-off-by: Bogdan Pricope --- platform/linux-generic/pktio/dpdk.c | 105 ++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 3 deletions(-) -- 1.9.1 diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index 58e6db0..b721bf6 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -27,6 +27,10 @@ #include #include #include +#include +#include +#include +#include #include static int disable_pktio; /** !0 this pktio disabled, 0 enabled */ @@ -772,6 +776,41 @@ fail: 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_to_mbuf(pktio_entry_t *pktio_entry, struct rte_mbuf *mbuf_table[], const odp_packet_t pkt_table[], uint16_t num) @@ -779,15 +818,30 @@ static inline int pkt_to_mbuf(pktio_entry_t *pktio_entry, pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; int i, j; char *data; + odp_packet_t pkt; uint16_t pkt_len; + packet_parser_t *pkt_p; + struct rte_mbuf *mbuf; + void *l3_hdr, *l4_hdr; + odp_bool_t ipv4_chksum_cfg, udp_chksum_cfg, tcp_chksum_cfg; + odp_bool_t ipv4_chksum_pkt, udp_chksum_pkt, tcp_chksum_pkt; + uint8_t l3_proto_v4, l4_proto; if (odp_unlikely((rte_pktmbuf_alloc_bulk(pkt_dpdk->pkt_pool, mbuf_table, num)))) { ODP_ERR("Failed to alloc mbuf\n"); return 0; } + + ipv4_chksum_cfg = pktio_entry->s.config.pktout.bit.ipv4_chksum; + udp_chksum_cfg = pktio_entry->s.config.pktout.bit.udp_chksum; + tcp_chksum_cfg = pktio_entry->s.config.pktout.bit.tcp_chksum; + for (i = 0; i < num; i++) { - pkt_len = _odp_packet_len(pkt_table[i]); + mbuf = mbuf_table[i]; + pkt = pkt_table[i]; + pkt_len = _odp_packet_len(pkt); + pkt_p = &odp_packet_hdr(pkt)->p; if (pkt_len > pkt_dpdk->mtu) { if (i == 0) @@ -796,9 +850,54 @@ static inline int pkt_to_mbuf(pktio_entry_t *pktio_entry, } /* Packet always fits in mbuf */ - data = rte_pktmbuf_append(mbuf_table[i], pkt_len); + data = rte_pktmbuf_append(mbuf, pkt_len); + + odp_packet_copy_to_mem(pkt, 0, pkt_len, data); + + if (!pktio_entry->s.config.pktout.all_bits) + continue; + + l3_hdr = (void *)(data + pkt_p->l3_offset); + + if (packet_parse(l3_hdr, &l3_proto_v4, &l4_proto)) + continue; + + ipv4_chksum_pkt = ipv4_chksum_cfg && l3_proto_v4; + udp_chksum_pkt = udp_chksum_cfg && + (l4_proto == _ODP_IPPROTO_UDP); + tcp_chksum_pkt = tcp_chksum_cfg && + (l4_proto == _ODP_IPPROTO_TCP); + + if (!ipv4_chksum_pkt && !udp_chksum_pkt && !tcp_chksum_pkt) + continue; + + mbuf->l2_len = pkt_p->l3_offset - pkt_p->l2_offset; + mbuf->l3_len = pkt_p->l4_offset - pkt_p->l3_offset; - odp_packet_copy_to_mem(pkt_table[i], 0, pkt_len, data); + 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 *)(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 i;