From nobody Thu Feb 24 13:04:25 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 6522D19DFDDE; Thu, 24 Feb 2022 13:04:26 +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 4K4CmB0mdFz4WBW; Thu, 24 Feb 2022 13:04:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645707866; 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=ld1KS0Avwr+l/KZg2yVSu5G1xMZxuyv1d4Ua7AUiulk=; b=wknSuwlquVdTtfQzp4No2xJNsoDcCtWBJY7Pid2fZ5VqA4fwP8/4iyoVhVquWnBsSps35w LtlPYVWIOGOJDbaOD8FQr4JHtbsV8E/of39HuPF2Sqp34bZHO5MQXDgjODu0sLierU+saS GkhVJHcwO+26JtY1QKqk71q+18dPqYjw27kBhHe3k122LymaAoFNMxwymgIeJa/DhoM9GE 7IU4xHsU27YD5jO7N1VCLZ95nSRDr4iVV3ypDD8Z97Ir4gvIzUuuPhOvJ+XaINZpEdrUo8 JAPa5ihL8+TMLXkS2koBoLjcQDUQ2IzXRVeF1Xn17NPQ+vCuoYGw9mT4n9GjIQ== 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 BFE504999; Thu, 24 Feb 2022 13:04:25 +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 21OD4PW4044123; Thu, 24 Feb 2022 13:04:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21OD4PFW044122; Thu, 24 Feb 2022 13:04:25 GMT (envelope-from git) Date: Thu, 24 Feb 2022 13:04:25 GMT Message-Id: <202202241304.21OD4PFW044122@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Marcin Wojtas Subject: git: 126a30da9cff - stable/12 - 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/stable/12 X-Git-Reftype: branch X-Git-Commit: 126a30da9cfffb5c8df029297a0219bf56b6fb53 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645707866; 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=ld1KS0Avwr+l/KZg2yVSu5G1xMZxuyv1d4Ua7AUiulk=; b=IOqRz+dBRUaldsXFPL54TY27v5/ns0cCWM+fvmthkN9yD41IXTXcE0yOZyyo+fHq/hB9QZ m9zlLbpInjCPKwiAMHVH5imTK+4ukQJ1a6aftKFtSy/KGkZ2VLBwVzYP/kWAanYvZRGUeg 5jRs05SB0mgwnl3YBMrL57gqEnujx0H+dTr2pJcuqWIr6pVtXTuD7mYCCYAIFzeukEgroK Em1cUGmgMulja+NC1yjkYqdFSaFskUoWdv2y9u/kfWz3CiFndEFItISKEaA1aNnS7kesmX n/oWRaVqib9gygR+U0zQ5RZs3kzkl8hEz98WrqQ/wV8pYObe9bZXu5dJDm69Tg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645707866; a=rsa-sha256; cv=none; b=qBIJtEwM55kvQ48Dnqx4aV/Nc8HjHa8ZfLPASEbCtKrCEoVpnsxYQO/UP+21faFB2gedQm R6In6hXhz5Qx+vUdoOKUGY8Rp+991pIpHCLANFaF6H6i9RQuEN4O+ZUOp1tbKbT5dc4uSs Zk2z43qke1J72Kj/gJtcctb+W9K8luqMLkv/PgIthJiYH/RSXQdHryPNN4201PHb/TgryF GCxdRH/vbzxptT6uItxaEtjWAh9AbntI6uQsz69blQaOrwPRTMjMcSMH/VReL2PQalsThQ ScnBmes7X0hiKbPHg6JvLQ0S75P3ghGESf9pX0+u1y/kTRArXWiVGCc2lx9Yyg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by mw: URL: https://cgit.FreeBSD.org/src/commit/?id=126a30da9cfffb5c8df029297a0219bf56b6fb53 commit 126a30da9cfffb5c8df029297a0219bf56b6fb53 Author: Dawid Gorecki AuthorDate: 2022-01-03 13:49:58 +0000 Commit: Marcin Wojtas CommitDate: 2022-02-24 13:04:04 +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. (cherry picked from commit 2bbef9d95dc10a69a3c5813a517f6e8fe583539a) --- 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 0a7dc51b1cdc..023a0d54693e 100644 --- a/sys/dev/ena/ena_datapath.c +++ b/sys/dev/ena/ena_datapath.c @@ -41,6 +41,8 @@ __FBSDID("$FreeBSD$"); #include #endif /* RSS */ +#include + /********************************************************************* * Static functions prototypes *********************************************************************/ @@ -713,6 +715,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; @@ -730,6 +733,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)); @@ -751,41 +757,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 */