From nobody Sun Jan 23 19:50:32 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id B62691980DC0; Sun, 23 Jan 2022 19:50:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JhkHX3lPHz3w6n; Sun, 23 Jan 2022 19:50:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642967432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=z0jRXlEFTPDbGOPohqR+6EKgmKJLiEbwIuvc/kYRNa8=; b=hI2x9WGmYNmQJFHiR2kwwPAfKLWDYGfY7Tce5dhQQzYt/mWzPWT1hfKlIucDz1b1NDWcv8 6gIolnW9uaaJMC8nR/axacza9mMbua8QEmIQJhr7Z8xs6lnAkzP+mtNt1oSyL6rxEyJkPd pJwjNioyb/boJftY8s4xa0tJQG4XdZUP9ehhip6abM/1uGrS1mb1VBfQDFRTXBmmmMrVai 4g/zxLVu+azRJw7YUhAobqw1Nd3SJFpOTiDhHtx2pkZlg8YEeS8gXFh4V6Gu+FGHd1m+gg dsB/9SHyruJVCDXgb8MfzclEG9f65/0M7YPfFY43zOMKDR4lRvDhcMaJ1SMmLQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 576FE2E6; Sun, 23 Jan 2022 19:50:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20NJoWCk058330; Sun, 23 Jan 2022 19:50:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20NJoWni058329; Sun, 23 Jan 2022 19:50:32 GMT (envelope-from git) Date: Sun, 23 Jan 2022 19:50:32 GMT Message-Id: <202201231950.20NJoWni058329@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Marcin Wojtas Subject: git: 2bbef9d95dc1 - main - ena: properly handle IPv6 L4 checksum offload List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mw X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2bbef9d95dc10a69a3c5813a517f6e8fe583539a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642967432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=z0jRXlEFTPDbGOPohqR+6EKgmKJLiEbwIuvc/kYRNa8=; b=aZYu5y18f2wwsC0O9sjrY7AWl5e4EAK2M0hNpbGoAUu/AYURMg1Z2W9QYVIHO0xiqRRI6T mpvAzNqpO4eEi7VYTVAfNj7IPhb+7TsgVSyolxr2WryIeVZErSUEfIIFFsb1iLusQw277D uQcK7px6l/GNIvGCwQxAmHW5aPjCwGsM/6Y3acBKXjV3DgDTtQjmX3yPdEvq345AFZAzWO PPxe/HiHCFUGZinu2aWUBAR/DdnKbEDwB9gcW3IFuKxEGiA5it/CrMZTfVKeVN0EnZTVAX YCrD+M1W5sj0r3yZJPy+PonP5uFuTlFmDzgXsZrsd/yR8F/8yI6REpGndVxwyg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642967432; a=rsa-sha256; cv=none; b=ygJ8+Kd5C7Q2mZobZ1lXO7eGtcEbYr81gEzE9TpoPPl8UEIw9k4MAnAe5OQbpFP+ynswrA EV5XrKUsPto7DzY+/mnk5Q2PzqX++nATSErdqjKtsjTNID4SG92bsAmpba8Y6HQ+xU4WDB X/zhXw5oI8dUxt4fd9V/HOJXzA8qjM9VxfiefLcjx8jzFxmxiUVCKRlusAgzeenYo4846j +WIEyyvrddOtNGRDgF9uGEdWR4s1wgSYDDE3gLBAZM60He+oWsTFVMNNe7A1zITYKbJf4i kRgeWIDpmao9B1sSjgQNRnL/p3vHj06y2aWH18ereu/cTJvoQdzEuvgMTi3T0A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mw: URL: https://cgit.FreeBSD.org/src/commit/?id=2bbef9d95dc10a69a3c5813a517f6e8fe583539a commit 2bbef9d95dc10a69a3c5813a517f6e8fe583539a Author: Dawid Gorecki AuthorDate: 2022-01-03 13:49:58 +0000 Commit: Marcin Wojtas CommitDate: 2022-01-23 19:38:01 +0000 ena: properly handle IPv6 L4 checksum offload ena_tx_csum function did not check if IPv6 checksum offload was requested it only checked checksum offloading flags for IPv4 packets. Because of that, when encountering CSUM_IP6_* flags, the function simply returned without actually setting checksum offloading in ena_ctx. Check CUSM_IP6_* flags to enable IPv6 checksum offload. Additionally, only IPv4 header was being parsed regardless of EtherType field, because of that, value of L4 protocol read when actually trying to send IPv6 packets was wrong. Use ip6_lasthdr function to get length of all IPv6 headers and payload protocol. Set the DF flag to 1 in order to allow the device to offload the IPv6 checksum calculation and achieve optimal performance. Add CSUM6_OFFLOAD and CSUM_OFFLOAD definitions into ena_datapath.h. Submitted by: Dawid Gorecki Obtained from: Semihalf MFC after: 2 weeks Sponsored by: Amazon, Inc. --- sys/dev/ena/ena_datapath.c | 44 ++++++++++++++++++++++++++++---------------- sys/dev/ena/ena_datapath.h | 1 + 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/sys/dev/ena/ena_datapath.c b/sys/dev/ena/ena_datapath.c index 0e6a6fe82038..3026671b6a19 100644 --- a/sys/dev/ena/ena_datapath.c +++ b/sys/dev/ena/ena_datapath.c @@ -40,6 +40,8 @@ __FBSDID("$FreeBSD$"); #include #endif /* RSS */ +#include + /********************************************************************* * Static functions prototypes *********************************************************************/ @@ -712,6 +714,7 @@ ena_tx_csum(struct ena_com_tx_ctx *ena_tx_ctx, struct mbuf *mbuf, uint16_t etype; int ehdrlen; struct ip *ip; + int ipproto; int iphlen; struct tcphdr *th; int offset; @@ -729,6 +732,9 @@ ena_tx_csum(struct ena_com_tx_ctx *ena_tx_ctx, struct mbuf *mbuf, if ((mbuf->m_pkthdr.csum_flags & CSUM_OFFLOAD) != 0) offload = true; + if ((mbuf->m_pkthdr.csum_flags & CSUM6_OFFLOAD) != 0) + offload = true; + if (!offload) { if (disable_meta_caching) { memset(ena_meta, 0, sizeof(*ena_meta)); @@ -750,41 +756,47 @@ ena_tx_csum(struct ena_com_tx_ctx *ena_tx_ctx, struct mbuf *mbuf, } mbuf_next = m_getptr(mbuf, ehdrlen, &offset); - ip = (struct ip *)(mtodo(mbuf_next, offset)); - iphlen = ip->ip_hl << 2; - - mbuf_next = m_getptr(mbuf, iphlen + ehdrlen, &offset); - th = (struct tcphdr *)(mtodo(mbuf_next, offset)); - - if ((mbuf->m_pkthdr.csum_flags & CSUM_IP) != 0) { - ena_tx_ctx->l3_csum_enable = 1; - } - if ((mbuf->m_pkthdr.csum_flags & CSUM_TSO) != 0) { - ena_tx_ctx->tso_enable = 1; - ena_meta->l4_hdr_len = (th->th_off); - } switch (etype) { case ETHERTYPE_IP: + ip = (struct ip *)(mtodo(mbuf_next, offset)); + iphlen = ip->ip_hl << 2; + ipproto = ip->ip_p; ena_tx_ctx->l3_proto = ENA_ETH_IO_L3_PROTO_IPV4; if ((ip->ip_off & htons(IP_DF)) != 0) ena_tx_ctx->df = 1; break; case ETHERTYPE_IPV6: ena_tx_ctx->l3_proto = ENA_ETH_IO_L3_PROTO_IPV6; - + iphlen = ip6_lasthdr(mbuf, ehdrlen, IPPROTO_IPV6, &ipproto); + iphlen -= ehdrlen; + ena_tx_ctx->df = 1; + break; default: + iphlen = 0; + ipproto = 0; break; } - if (ip->ip_p == IPPROTO_TCP) { + mbuf_next = m_getptr(mbuf, iphlen + ehdrlen, &offset); + th = (struct tcphdr *)(mtodo(mbuf_next, offset)); + + if ((mbuf->m_pkthdr.csum_flags & CSUM_IP) != 0) { + ena_tx_ctx->l3_csum_enable = 1; + } + if ((mbuf->m_pkthdr.csum_flags & CSUM_TSO) != 0) { + ena_tx_ctx->tso_enable = 1; + ena_meta->l4_hdr_len = (th->th_off); + } + + if (ipproto == IPPROTO_TCP) { ena_tx_ctx->l4_proto = ENA_ETH_IO_L4_PROTO_TCP; if ((mbuf->m_pkthdr.csum_flags & (CSUM_IP_TCP | CSUM_IP6_TCP)) != 0) ena_tx_ctx->l4_csum_enable = 1; else ena_tx_ctx->l4_csum_enable = 0; - } else if (ip->ip_p == IPPROTO_UDP) { + } else if (ipproto == IPPROTO_UDP) { ena_tx_ctx->l4_proto = ENA_ETH_IO_L4_PROTO_UDP; if ((mbuf->m_pkthdr.csum_flags & (CSUM_IP_UDP | CSUM_IP6_UDP)) != 0) diff --git a/sys/dev/ena/ena_datapath.h b/sys/dev/ena/ena_datapath.h index 8da6a2a0edc9..f3b721359c72 100644 --- a/sys/dev/ena/ena_datapath.h +++ b/sys/dev/ena/ena_datapath.h @@ -40,5 +40,6 @@ int ena_mq_start(if_t ifp, struct mbuf *m); void ena_deferred_mq_start(void *arg, int pending); #define CSUM_OFFLOAD (CSUM_IP|CSUM_TCP|CSUM_UDP) +#define CSUM6_OFFLOAD (CSUM_IP6_UDP|CSUM_IP6_TCP) #endif /* ENA_TXRX_H */