From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0082.outbound.protection.outlook.com [104.47.0.82]) by dpdk.org (Postfix) with ESMTP id 79DE11BB3E for ; Sun, 24 Jun 2018 01:17:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RTvTTMhy8ihwxJ/LuKRHUiH3Ibn4SrpJ8s1MXNz03qQ=; b=KYBAWnCedyldlNEfdN9RBIsubiqrWTvHbb/1lvXzT+njB3JGggptgu9kHD1KjtsXxHdr+D6wck27n6DmUSf74RebWdIT25zGHEuMs3436uJvammcCUF4uVbAkJCE23FeTEr+8wmXf77QJVvzrJoE1d728RkegtWKyLTnTbiNkTQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ophirmu@mellanox.com; Received: from mellanox.com (37.142.13.130) by HE1PR0501MB2314.eurprd05.prod.outlook.com (2603:10a6:3:27::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.884.23; Sat, 23 Jun 2018 23:17:56 +0000 From: Ophir Munk To: dev@dpdk.org, Keith Wiles Cc: Thomas Monjalon , Olga Shern , Ophir Munk Date: Sat, 23 Jun 2018 23:17:40 +0000 Message-Id: <1529795861-1361-2-git-send-email-ophirmu@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1529795861-1361-1-git-send-email-ophirmu@mellanox.com> References: <1528821108-12405-3-git-send-email-ophirmu@mellanox.com> <1529795861-1361-1-git-send-email-ophirmu@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR0901CA0090.eurprd09.prod.outlook.com (2603:10a6:800:7e::16) To HE1PR0501MB2314.eurprd05.prod.outlook.com (2603:10a6:3:27::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3570cae4-1903-48a2-c756-08d5d95f8e41 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600026)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:HE1PR0501MB2314; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2314; 3:OdBz+2fkGh596TlXaSGxWLLRCmGkXw+ER3/F3vuU5HjIyjQNBSkHWhmXo5dwAYq9b/mvOIVOLx94qTTPCdR8vSPqJGP6dy0wIunN2ze5P2EEjXO0Jcwmy8oJ8AtOSP0tUQWQLYIedfBh94Q5ityYhCJmPi3UfwoKpwcfLseCQUTfU5JO9V7bRkPmPC8gaLQSbqc7tlVcc+9osGYu9shiReuJr2ZD25CBJ8aCF7qIav3ho6CNf9m4w6AlLudO/FBn; 25:MXzcCiEFpzIqCgWfzL0KDc4dp1xpTXdgT0UxT7ax6fx7J/JbAK8/COoo10vSoko6QsZRkrYKyUKOgvlkDTTzAtkKiwHXIyKIKq6srVk2j9Q9odhl1kCw3JYUSJAMINydN7Wl7MDYB4bTH7XqmpJENhbfpwpx5+8TEGVZ8Py1b7NnW2y0tDgLMrtdW8aO4s25vLg6liRMn5gW6EVU0UQ6NTlhDS/VyFa0W6VeSuEKo/u2DGHGuePHi8R/fsNWuwCxFY81HWOOZdYhDrXWmLCAK/6xOR32fNzyoORZis7ld+j4sXB8XjMgbQgSKRLOhufaGHv0doByP+NFAIHm9mA/Jw==; 31:6uafbfOU6P3tghHZca+L+usKXG/kuA4ygHqEn3f5RbdPTUPWsN3OpUpgOZSZ676qOjjrd5/uKju70XRW6evYlXCrwqJOMkgp+fxLbTOTLQmbsaeTRXE1wiYYPQCn+P6nnjRxhjilhRa8syZwIxrlGWjSDFx7wrv/tH/ANUnem+OmskoVIuIwXybRJtizZgA1diQWwgM7heonobPZrOOt8zZQjl/27BrMm5LiJhYMXHs= X-MS-TrafficTypeDiagnostic: HE1PR0501MB2314: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2314; 20:VdPBq/I/2maOMe8WNKFuVC6CZZMuGQBFEVaRuBCsqIcpOWLnkAS1/zACPaBzVIHWn3F0Dcy/HYMK6TZeSZi2/PwAoq6eITtuxluQFpLI97KumM4DkyTJGEgTZ2pBtCD5d/yR+VMcXj7RDOTrt69/5PWwrtC5P1WVmkb+kfrSAvpvWfEkTmCQkRjsCFpLBX6wk0K+tnGqf/oabXlvwoyf+XVLF+OeaTV8SfFwiGYLuZO2+JBaebhBEPgymh+HpwMR5PndsRHVARfd7I0UqL3S3V4tNW/av2qCL1rNCEn3HcxCousDMohkbAJdgwlUdu2KX47QcakXTWo+yx8/BvD3RNLa6ILVGmSRRCn0cnmzX7lkATR5MKZA+qlo1TIAx6WznV4wYDSZp+k3m+8CN17zPqhIlZnu4ZTxf05LNkc+LxHKO/Wxv1cYfLdgP0QpMFF+pAy0282LxXKyAaKOgIQJAED3ev/z3bw1fk2riCvgPTO1QZ5t+d7jothSEcViibXl; 4:xl1sR9vdJwH61Exx7s2oIRiKWUEXffZflIayngh/srlQsNp6LhqPveU9lBe+IfBD920754mBt15CU55HIjfRcwRQH/ZlWVqTSrfWCBQQoWyqEekFcwUGChwVyOfUwmGmFGy1065I/nPbD/ntkGL2JUwlebamcHAkPoGWew25nRZkcjDs+tEdbKrDn88sbTktB+RyfFeneQV5A63oqVJskg3s3qZkwUfDg4wBKZ9XXStAr00vpFmlVmXycBW9qzVDSBP9wW0116knS+xkMiXxvA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:HE1PR0501MB2314; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0501MB2314; X-Forefront-PRVS: 07126E493C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(396003)(39860400002)(346002)(39380400002)(376002)(199004)(189003)(26005)(86362001)(7696005)(16526019)(51416003)(7736002)(52116002)(55016002)(6666003)(2906002)(107886003)(4326008)(8936002)(4720700003)(16586007)(21086003)(186003)(36756003)(69596002)(3846002)(6116002)(59450400001)(76176011)(386003)(66066001)(47776003)(5660300001)(106356001)(316002)(105586002)(6916009)(53936002)(956004)(476003)(68736007)(48376002)(446003)(486006)(54906003)(50466002)(8676002)(81156014)(2616005)(81166006)(478600001)(11346002)(50226002)(25786009)(305945005)(33026002)(97736004); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0501MB2314; H:mellanox.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0501MB2314; 23:XjeC/aaqJudYaAi6JcgEGmZViHEl3SxnewdIwy4?= =?us-ascii?Q?W/4735VV0wuYstQw0zaFh8MmKTqGYVcYY1xSN1GrLYuh+CjXAB/fmijcKPfM?= =?us-ascii?Q?plMRWWs8eOpzrsfrUWouIkSIS/Xd0U9MrQbCYcQ3fWAAuJ6DOEX0UJ5YcbCT?= =?us-ascii?Q?oJCisJutVGVxnAKd4DbjBQZCCE/1Zehbpi7cuPNxIeVXrLdSBy0XdnidPlYs?= =?us-ascii?Q?t7iWon2By5MK29Wf88aFrwqqSV/akpvKP6sCbLhC0kVR9t6gqOpzr5svnOiy?= =?us-ascii?Q?PsHW/V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x8kR9yUksJYg==; 5:mEcIPpsOQzfQrsrZYvwKMK53ZBT0AEZ/nf1x4j4fWItsafTbIDB/jBFOY8QJU+SAW73cQG/tPI5Lx1qsJyAL2vimLH+Xqrt25bYZxHP9sjjmS6YYm7JUbxujD+6bHuUmEc7suOQg4jEDEPuMoaxkmLmniFNZBD5OjsU/8OL4i9o=; 24:9MnMQUHXrEcxTLTf2yBAL4N7OLyyz9qtgsJeZaS7wp3AUi86qrrfvsRshzpKawJv55mQ8gy2+eSrG99LeK73MAAmjzei5ILetHmhuBasjNU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2314; 7:lBaJjkalWmK+RBrN52Su2+xjVwHxYs/18e1OQBpuXnkGzHSUR3WMTxOq1z96oQQ+FF8+QUpqNdvf2Gzz8a2rJvbLZHW14r8NIMg9HS0z6w8vy9cnkq6x78lUGd4zf/2OXJsJUv6c+Aem0O83ccULKHMJ2SmlUQd3kXhQKY/+R8vFZaYbUmGzjDLJi3ITdTxy5VccZveWe3Vjtai3NAFC45MgVNK3Mt08xCVwAcSeyAaY9oEBSVaZM0Lz2vn+9i5P X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2018 23:17:56.4480 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3570cae4-1903-48a2-c756-08d5d95f8e41 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0501MB2314 Subject: [dpdk-dev] [PATCH v5 1/2] net/tap: calculate checksums of multi segs packets X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Jun 2018 23:17:59 -0000 Prior to this commit IP/UDP/TCP checksum offload calculations were skipped in case of a multi segments packet. This commit enables TAP checksum calculations for multi segments packets. The only restriction is that the first segment must contain headers of layers 3 (IP) and 4 (UDP or TCP) Reviewed-by: Raslan Darawsheh Signed-off-by: Ophir Munk --- drivers/net/tap/rte_eth_tap.c | 161 ++++++++++++++++++++++++++++++------------ 1 file changed, 114 insertions(+), 47 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index df396bf..8903646 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -415,9 +415,41 @@ tap_tx_offload_get_queue_capa(void) DEV_TX_OFFLOAD_TCP_CKSUM; } +/* Finalize l4 checksum calculation */ static void -tap_tx_offload(char *packet, uint64_t ol_flags, unsigned int l2_len, - unsigned int l3_len) +tap_tx_l4_cksum(uint16_t *l4_cksum, uint16_t l4_phdr_cksum, + uint32_t l4_raw_cksum) +{ + if (l4_cksum) { + uint32_t cksum; + + cksum = __rte_raw_cksum_reduce(l4_raw_cksum); + cksum += l4_phdr_cksum; + + cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff); + cksum = (~cksum) & 0xffff; + if (cksum == 0) + cksum = 0xffff; + *l4_cksum = cksum; + } +} + +/* Accumaulate L4 raw checksums */ +static void +tap_tx_l4_add_rcksum(char *l4_data, unsigned int l4_len, uint16_t *l4_cksum, + uint32_t *l4_raw_cksum) +{ + if (l4_cksum == NULL) + return; + + *l4_raw_cksum = __rte_raw_cksum(l4_data, l4_len, *l4_raw_cksum); +} + +/* L3 and L4 pseudo headers checksum offloads */ +static void +tap_tx_l3_cksum(char *packet, uint64_t ol_flags, unsigned int l2_len, + unsigned int l3_len, unsigned int l4_len, uint16_t **l4_cksum, + uint16_t *l4_phdr_cksum, uint32_t *l4_raw_cksum) { void *l3_hdr = packet + l2_len; @@ -430,38 +462,21 @@ tap_tx_offload(char *packet, uint64_t ol_flags, unsigned int l2_len, iph->hdr_checksum = (cksum == 0xffff) ? cksum : ~cksum; } if (ol_flags & PKT_TX_L4_MASK) { - uint16_t l4_len; - uint32_t cksum; - uint16_t *l4_cksum; void *l4_hdr; l4_hdr = packet + l2_len + l3_len; if ((ol_flags & PKT_TX_L4_MASK) == PKT_TX_UDP_CKSUM) - l4_cksum = &((struct udp_hdr *)l4_hdr)->dgram_cksum; + *l4_cksum = &((struct udp_hdr *)l4_hdr)->dgram_cksum; else if ((ol_flags & PKT_TX_L4_MASK) == PKT_TX_TCP_CKSUM) - l4_cksum = &((struct tcp_hdr *)l4_hdr)->cksum; + *l4_cksum = &((struct tcp_hdr *)l4_hdr)->cksum; else return; - *l4_cksum = 0; - if (ol_flags & PKT_TX_IPV4) { - struct ipv4_hdr *iph = l3_hdr; - - l4_len = rte_be_to_cpu_16(iph->total_length) - l3_len; - cksum = rte_ipv4_phdr_cksum(l3_hdr, 0); - } else { - struct ipv6_hdr *ip6h = l3_hdr; - - /* payload_len does not include ext headers */ - l4_len = rte_be_to_cpu_16(ip6h->payload_len) - - l3_len + sizeof(struct ipv6_hdr); - cksum = rte_ipv6_phdr_cksum(l3_hdr, 0); - } - cksum += rte_raw_cksum(l4_hdr, l4_len); - cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff); - cksum = (~cksum) & 0xffff; - if (cksum == 0) - cksum = 0xffff; - *l4_cksum = cksum; + **l4_cksum = 0; + if (ol_flags & PKT_TX_IPV4) + *l4_phdr_cksum = rte_ipv4_phdr_cksum(l3_hdr, 0); + else + *l4_phdr_cksum = rte_ipv6_phdr_cksum(l3_hdr, 0); + *l4_raw_cksum = __rte_raw_cksum(l4_hdr, l4_len, 0); } } @@ -482,17 +497,27 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) max_size = *txq->mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN + 4); for (i = 0; i < nb_pkts; i++) { struct rte_mbuf *mbuf = bufs[num_tx]; - struct iovec iovecs[mbuf->nb_segs + 1]; + struct iovec iovecs[mbuf->nb_segs + 2]; struct tun_pi pi = { .flags = 0, .proto = 0x00 }; struct rte_mbuf *seg = mbuf; char m_copy[mbuf->data_len]; + int proto; int n; int j; + int k; /* first index in iovecs for copying segments */ + uint16_t l234_hlen; /* length of layers 2,3,4 headers */ + uint16_t seg_len; /* length of first segment */ + uint16_t nb_segs; + uint16_t *l4_cksum; /* l4 checksum (pseudo header + payload) */ + uint32_t l4_raw_cksum = 0; /* TCP/UDP payload raw checksum */ + uint16_t l4_phdr_cksum = 0; /* TCP/UDP pseudo header checksum */ + uint16_t is_cksum = 0; /* in case cksum should be offloaded */ /* stats.errs will be incremented */ if (rte_pktmbuf_pkt_len(mbuf) > max_size) break; + l4_cksum = NULL; if (txq->type == ETH_TUNTAP_TYPE_TUN) { /* * TUN and TAP are created with IFF_NO_PI disabled. @@ -505,35 +530,77 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) * is 4 or 6, then protocol field is updated. */ char *buff_data = rte_pktmbuf_mtod(seg, void *); - j = (*buff_data & 0xf0); - pi.proto = (j == 0x40) ? rte_cpu_to_be_16(ETHER_TYPE_IPv4) : - (j == 0x60) ? rte_cpu_to_be_16(ETHER_TYPE_IPv6) : 0x00; + proto = (*buff_data & 0xf0); + pi.proto = (proto == 0x40) ? + rte_cpu_to_be_16(ETHER_TYPE_IPv4) : + ((proto == 0x60) ? + rte_cpu_to_be_16(ETHER_TYPE_IPv6) : + 0x00); } - iovecs[0].iov_base = π - iovecs[0].iov_len = sizeof(pi); - for (j = 1; j <= mbuf->nb_segs; j++) { - iovecs[j].iov_len = rte_pktmbuf_data_len(seg); - iovecs[j].iov_base = - rte_pktmbuf_mtod(seg, void *); - seg = seg->next; - } + k = 0; + iovecs[k].iov_base = π + iovecs[k].iov_len = sizeof(pi); + k++; + + nb_segs = mbuf->nb_segs; if (txq->csum && ((mbuf->ol_flags & (PKT_TX_IP_CKSUM | PKT_TX_IPV4) || (mbuf->ol_flags & PKT_TX_L4_MASK) == PKT_TX_UDP_CKSUM || (mbuf->ol_flags & PKT_TX_L4_MASK) == PKT_TX_TCP_CKSUM))) { - /* Support only packets with all data in the same seg */ - if (mbuf->nb_segs > 1) + is_cksum = 1; + + /* Support only packets with at least layer 4 + * header included in the first segment + */ + seg_len = rte_pktmbuf_data_len(mbuf); + l234_hlen = mbuf->l2_len + mbuf->l3_len + mbuf->l4_len; + if (seg_len < l234_hlen) break; - /* To change checksums, work on a copy of data. */ + + /* To change checksums, work on a + * copy of l2, l3 l4 headers. + */ rte_memcpy(m_copy, rte_pktmbuf_mtod(mbuf, void *), - rte_pktmbuf_data_len(mbuf)); - tap_tx_offload(m_copy, mbuf->ol_flags, - mbuf->l2_len, mbuf->l3_len); - iovecs[1].iov_base = m_copy; + l234_hlen); + tap_tx_l3_cksum(m_copy, mbuf->ol_flags, + mbuf->l2_len, mbuf->l3_len, mbuf->l4_len, + &l4_cksum, &l4_phdr_cksum, + &l4_raw_cksum); + iovecs[k].iov_base = m_copy; + iovecs[k].iov_len = l234_hlen; + k++; + + /* Update next iovecs[] beyond l2, l3, l4 headers */ + if (seg_len > l234_hlen) { + iovecs[k].iov_len = seg_len - l234_hlen; + iovecs[k].iov_base = + rte_pktmbuf_mtod(seg, char *) + + l234_hlen; + tap_tx_l4_add_rcksum(iovecs[k].iov_base, + iovecs[k].iov_len, l4_cksum, + &l4_raw_cksum); + k++; + nb_segs++; + } + seg = seg->next; + } + + for (j = k; j <= nb_segs; j++) { + iovecs[j].iov_len = rte_pktmbuf_data_len(seg); + iovecs[j].iov_base = rte_pktmbuf_mtod(seg, void *); + if (is_cksum) + tap_tx_l4_add_rcksum(iovecs[j].iov_base, + iovecs[j].iov_len, l4_cksum, + &l4_raw_cksum); + seg = seg->next; } + + if (is_cksum) + tap_tx_l4_cksum(l4_cksum, l4_phdr_cksum, l4_raw_cksum); + /* copy the tx frame data */ - n = writev(txq->fd, iovecs, mbuf->nb_segs + 1); + n = writev(txq->fd, iovecs, j); if (n <= 0) break; -- 2.7.4