From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0045.outbound.protection.outlook.com [104.47.1.45]) by dpdk.org (Postfix) with ESMTP id 8294B2C6A for ; Mon, 7 May 2018 23:54:38 +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; bh=ZimCP6ebSvnSmWwDLd4IjBswhYmKqhrQV+zCHxax2XU=; b=jYpuDVdY5Orj3wBPNUCeMDuBqGNnFHCtzt29tLaLbPkbx+l/ti54km+0kVPx3JpClvn90a0nOwl8ltEqR7cLTSaZDPUerz05B/RdcY/bsH2c5xIf7hvikvdHvaAOKo5/JArwiJGF1mRP1PSmzZZog4NnacJ5BMnzc+ZrQLqF+lM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ophirmu@mellanox.com; Received: from mellanox.com (37.142.13.130) by VI1PR0501MB2320.eurprd05.prod.outlook.com (2603:10a6:800:2c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.735.18; Mon, 7 May 2018 21:54:35 +0000 From: Ophir Munk To: dev@dpdk.org, Pascal Mazon Cc: Thomas Monjalon , Olga Shern , Ophir Munk Date: Mon, 7 May 2018 21:54:22 +0000 Message-Id: <1525730063-28366-2-git-send-email-ophirmu@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1525730063-28366-1-git-send-email-ophirmu@mellanox.com> References: <1524396611-22391-2-git-send-email-ophirmu@mellanox.com> <1525730063-28366-1-git-send-email-ophirmu@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1P194CA0041.EURP194.PROD.OUTLOOK.COM (2603:10a6:803:3c::30) To VI1PR0501MB2320.eurprd05.prod.outlook.com (2603:10a6:800:2c::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:VI1PR0501MB2320; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2320; 3:g5g7bmKX5V8oBNLJT6ApylvI2sQLMRmkWNbgsB8teuutODJJYpJHh6JCtnReJNgOI6GhftKv969mCi4d+ACqLTz2rfPLD7tOx16w+Ir4wPTq+orJUMpKmpYBHf3pyh4H/ZIcVt4LUZK9r0Nv21IN19hpFrRxtUrFsKhsK1LSGoxBnINDihyTwXP2aZjSIH3H7OPSv0pu29ElQifLHPXag9WSZlWO55r3MLfZIqZwzdVk4r0EYaQgSLfFcz4I8FWj; 25:5W/kdHEHtSqTo+wJgMAyQG3ovXNmb3+6gXj1oeJTCnUJ406QU1VAVwd3z//zBTdFKJb8a2T7mfFucn8D8hiE20EPiP3R2b61iZG+6Q0/TfgHWeLsLmJHuT/FxcnmoGIItK0k4zuTlFhCE5e09MC5HHZjfD3xV5eyG588NLOsmeHuzOFq1LSWnDcfevcVdphkkRROo3Isld+OkmHLdBewTrPHSEOfzv+d2SIqao48H1k9iCF2WQ/ypbc+NPn+6OLASimHM+Vx6o5M+9g7Vo/i/yBMP4i2LkEfwjIQi3W1rjLkqQHXFK60eM0d+UYPUiFtFtYZ1XquJ+0GH+vKn2X8VA==; 31:hpkseARBpHFks8IbUKRcAVRBlijs1pDybae7pzISS40aLW7H565qIUWWDYV9pHGIFJ/wlFi7qvOBf8SAFT9rSFMuEQULLcMvR6n0aZRxmgmzrq2NCK/JJYkOYyRTriWaKuziAKyTSWfUrx4bVwQ5Qg7eoyVkFer+kDv/cwsgt6GoXIBWBXGH/yHWhMOEcZjtiQbKkLRlj3F/QESQs8BzWtNfvigmC06OHldm2PLB9Nk= X-MS-TrafficTypeDiagnostic: VI1PR0501MB2320: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2320; 20:okcegg6BB5kTKC1YsZBf76JSHakZXY9n7azfhYG9vf230+z9Gxilh3GLs/fzBs8po/wVNlmjKIUIsivonuhfjt+PL4gVtJchikPUN5F9fvCq8EAnirAc0f8HAtDddBgT99qVb0ezuB4U9mZg9TKM/ZqdUIPEIh+piBbRyAbH4Fbc33vveG1Ayqg9IA8pGo2H2MEk+Zs8+NB4Xcv4DbDVgmWudwA2kRAbEK2PVyPdGUs1701GntKLcYLxeFDZpwDJJRy14nvgsW+jGyOQftEc8QoLcvPlTyRcjPFXf9aZF5+6dxpTut+8A+ALDAal4LrfH2u4vd6cGaVBUv7Sbdoh8bn2+LHd6pszthpNaJzTpc42FjvgfcW6By0jyi0itCZA3Sp7/Is5jgHj2oSnsTTCBMmQ1tJa2aAJu/Ck5kWHD9UYb1sc8K4PeeDoNbLvRHupbkyw7396O4zYtilLL9tfCEkAZApbfslVo6q/aVtxTZvF9Sh3q/tJM3FTsnVIf3qh; 4:HwEiHBMoLjS0arnWWEJHWv0D7H7Xr09TcdLi2EIvrubHr81ycXOKeTrbS/jrm4nyjKufNpF7wYg04JHpme5zHml8J5UCx5gXtWfIStgH46mAVJTVUBuaR9Lwy4aNUE3krnYKLL8gHI1wck5PhBTCBeuGShjo4/6teI25BuwZedgTvIfx9hCMVV+mqTkWClwo0A8Eh+7OEZiUADdyWYq4LX8xCFwI1qHnX0Ph6k966As0xOPyDuGMkEjynkfhp2zc+SZBRJ9bpypQ5KTTFcljdg== 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)(8121501046)(5005006)(10201501046)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(6055026)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(6072148)(201708071742011); SRVR:VI1PR0501MB2320; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0501MB2320; X-Forefront-PRVS: 066517B35B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(396003)(346002)(376002)(39380400002)(366004)(199004)(189003)(4720700003)(97736004)(6916009)(81166006)(6666003)(7736002)(106356001)(8676002)(81156014)(305945005)(105586002)(5660300001)(54906003)(16586007)(21086003)(8936002)(316002)(33026002)(3846002)(478600001)(2906002)(6116002)(50226002)(48376002)(2616005)(36756003)(50466002)(51416003)(7696005)(52116002)(76176011)(4326008)(47776003)(86362001)(107886003)(59450400001)(486006)(386003)(476003)(956004)(446003)(69596002)(11346002)(66066001)(68736007)(53936002)(26005)(186003)(25786009)(55016002)(16526019); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0501MB2320; 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; VI1PR0501MB2320; 23:fVD42TtVYcM63asY1szp78MhWsLs41h8c+mOCui?= =?us-ascii?Q?xi4K+rKexhBlNSczHFErg5DZGH5c93TG2YW8B2rbBiAzRaNq7SEbiMieULaa?= =?us-ascii?Q?4yQGhD60bxYl1V3MAd3JHjlw15WFiQ04JlZQCBwAfWved9yJOOf2VH7BRZHz?= =?us-ascii?Q?9v4R8R7o1E3cICrbos785GHWXvJvPgt6+pHxkwCKoRBnn8xs5rAMxWi40WrC?= =?us-ascii?Q?un/eabHHw9jpFRvkrO1ynxKiRCnvRg+jkWKSaw2mCqCN2EC7IRsw9x6mByu0?= =?us-ascii?Q?5XZbu4rpuf+A9oP3Yl+WNxmbmDC4wRlGlBYeJmeHE8k3WjjTpLStMgbbKjXg?= =?us-ascii?Q?n2NrkQ/pvWa0NG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gh5jsn8csUWjKnCLmbQ8c9zh3cxOCc30OhU/N/XFQgP3ZLOthAPKe/8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2320; 7:hcxkOOEF5qtB5SMosBTfTKE81Eal7cDemzE9wC51/qcsDdTco7jQfNPL/o1xuTUlpsISOmpLm/SUy5Cld+kjWSz2WYigFXt7ePzm91b4eOrrIMCkQyaU82LMEhWc7kt/Lu+agT8y2kB1a11rFlmPN07oIHe6CVig509Ll0x1knLUS+JG14oxLK5LFPKHbrbr1q09GAzv2rz3d68W29GituXyUIlZBR2xOt3b+6WRtr/7EkR/ffG+jZyuEQ3rXuq9 X-MS-Office365-Filtering-Correlation-Id: d26eae3d-65d2-4ec4-4d97-08d5b4651fef X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2018 21:54:35.5453 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d26eae3d-65d2-4ec4-4d97-08d5b4651fef X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0501MB2320 Subject: [dpdk-dev] [PATCH v3 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: Mon, 07 May 2018 21:54:38 -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 | 158 +++++++++++++++++++++++++++++------------- 1 file changed, 108 insertions(+), 50 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 172a7ba..538acae 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -424,12 +424,43 @@ tap_txq_are_offloads_valid(struct rte_eth_dev *dev, uint64_t offloads) return true; } +/* 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) { - void *l3_hdr = packet + l2_len; + 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; if (ol_flags & (PKT_TX_IP_CKSUM | PKT_TX_IPV4)) { struct ipv4_hdr *iph = l3_hdr; uint16_t cksum; @@ -439,38 +470,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); } } @@ -491,17 +505,26 @@ 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; /* * TUN and TAP are created with IFF_NO_PI disabled. * For TUN PMD this mandatory as fields are used by @@ -513,34 +536,69 @@ pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) * value 0x00 is taken for protocol field. */ char *buff_data = rte_pktmbuf_mtod(seg, void *); - j = (*buff_data & 0xf0); - pi.proto = (j == 0x40) ? 0x0008 : - (j == 0x60) ? 0xdd86 : 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; - } + proto = (*buff_data & 0xf0); + pi.proto = (proto == 0x40) ? 0x0008 : + (proto == 0x60) ? 0xdd86 : 0x00; + + 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