From nobody Thu Feb 24 12:55:44 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 BF93319DD217; Thu, 24 Feb 2022 12:55:45 +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 4K4CZ91641z4SGF; Thu, 24 Feb 2022 12:55:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645707345; 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=Jel/UAb+FdtVNbNQZ/nhm2WUbeUQ6Ty6S9h+dfNJad8=; b=ovgLwX0jNfAzWtY1TifzAlkn/T3rLQNC8XCzwFyaFr8RsMK78RdB0J9jFaYIiwsBL0l7X9 w2vJckFKJtv6L+/N4NX2if3hAZagsJc67B381Ah2K3B+eyb1ZDwERmK1zdaBJHnwj2gZAw aQYM2Uad7hg5iPJbHop7M9KOZwMxgcKLSrm81S1mc4FXgtMhNouIyto7tcIO75S6hKlULm NQL57LYe+su9fNK66GmqAzkUK5NT9r7CHdzzu7F4S5urKnD+QODf7LNoJpF3AnPHuZxPlb iYug29MP5FLr/yMCjodn2eqyWZhlKPi5Li/JpfIVp8WrxbY5PHEUGOzQc52XVw== 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 F144147E1; Thu, 24 Feb 2022 12:55:44 +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 21OCtiZE029997; Thu, 24 Feb 2022 12:55:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21OCtibj029996; Thu, 24 Feb 2022 12:55:44 GMT (envelope-from git) Date: Thu, 24 Feb 2022 12:55:44 GMT Message-Id: <202202241255.21OCtibj029996@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: eff45c1e6627 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: eff45c1e66279c56cbb2e53ad89cffcce2c1ed1d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645707345; 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=Jel/UAb+FdtVNbNQZ/nhm2WUbeUQ6Ty6S9h+dfNJad8=; b=L2OiKc/D2ik1NlFl5x8beynYTcnwn9/Or1qu8ECBqArc+scYZ00/llYWXxnFAYVvNQs530 6RDohpEviqqM4zOqOEqfiSK1LBdVGpG6VGmRhBxdHFrHtvPYPRrxMFxPwX422nI4+puTR4 p0Ha6FZGsva0XYO1BNstzb9v5lluCYnIuqWU//A3KexJ66yTShLHmGDdhR1LrPV3zApnRP 76EKIxaFdyURtMeMwXK1fygSZVr+G5sClz2En3VzAzUCmWoAldpuvQko4/YsfSqUImd9FW EDrHUtJWaYhZ+4NMDOT1QiEliJqFixkpg6trmRvafAsjYEXGQNhJVlD0a5QPDw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645707345; a=rsa-sha256; cv=none; b=qGD18lHrpwNYaXCSQin2Wgef2jkwqb0JrnXo4UD8H6Xc/8WkCyR5M9BXvMHi6zVATTD/Ld NLqsh4fLgH8as+SCxDn9vqHJt0CiUs0p8yWQ+0hjIc7b+5L7jWI3OyTFN+IiA54u7bwvBX vQjBvhtKkCDCg8TtScRFeLjPH4g/3xAxLi1+fi6C/mfRL+NeHrlIADsMC25TyIopiobDnk 8FDw0OKNVWkGqRoC7bJuN4scCrOnhDCD9lQdKA6vGab/eM++Kx8f1ak+URZIEQkjbK1tSO WadRrXRg7qksbWW094Al55RJsgRm8G3BjGhyPUntgDqkZihvY39TIRIQeSinvw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mw: URL: https://cgit.FreeBSD.org/src/commit/?id=eff45c1e66279c56cbb2e53ad89cffcce2c1ed1d commit eff45c1e66279c56cbb2e53ad89cffcce2c1ed1d Author: Dawid Gorecki AuthorDate: 2022-01-03 13:49:58 +0000 Commit: Marcin Wojtas CommitDate: 2022-02-24 12:53:43 +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 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 */