From nobody Thu Mar 13 16:03:18 2025 X-Original-To: dev-commits-src-main@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 4ZDC2v20dmz5qrn5; Thu, 13 Mar 2025 16:03:19 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZDC2t4W4Wz3QSR; Thu, 13 Mar 2025 16:03:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741881798; 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=BgzRGemus91G90LCcJTcYhu3+Wq6rJrNotaPdQhqPEc=; b=YzuUTWevwROCEn1L5Y7p3g656I/94A63h6S8G5ct5sETRW0C7Ba2w4xUNIX2d6KvVJBR+4 gxWSR34ZKXD25ugQdmAH972GAJNoLt52F1M+AGi2zdYgjgnjb/AQJyYclb7wZuR3M9rK/B z+kRoMaf7bOTRT4mJNfP4QdFOp5mWaaS5ydS4KRWPnggGW/Jj9A5BeLBAmdeEz7s/CM8Bw f3uArK8KN1zjD4WAGjDByfdYBYd5N3ldhz9/QR2EWHZtvetrzApwJvS6SAO6mdUSFO6LVs oFFVDtdabnDIclTy4lyBRsFMXFdNkXiQ0t/UIgycjUBAdlyT2aAewnu29EHuMw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1741881798; a=rsa-sha256; cv=none; b=GBB3rTQSgtToTTrl1w5qhZ7/DD5p4HUJeMl2M6oW0qtf3Zm3PvADbXoNfjhzYqGNe7lIOJ FIWzLlw67/Z8kFg49wGunkuDbQ+6gzTNKk4f7kkOfda30T25TJhS+zTi1lnplHzFrqMq0l Sp9avoXh2AqVc7ZbvIwbIZrahJlTAcnnLuwvS5EPJFZ/KsZMhUPcrqlIk8jaTRDxI91TWm SGqxlvG7oZG4U8xLck1ZepvKqqSwirs5wz8GeNacYR/ocuUXezCuUfZkF8PPlxq1+2v/0b Hg5zVg4gBkF5JrCQM13StJkYVMlWncBIkR3nyXDlH5hApd98uJx6CG5jVuQ8xw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741881798; 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=BgzRGemus91G90LCcJTcYhu3+Wq6rJrNotaPdQhqPEc=; b=ZQ/lVWsq7ePUR/ToTLSVHG0VymGfMQT+zj62jPBAq15W60E2BF5v2Duau5Rso0obcIAUn2 N9SNY/4hwmR8HbM8MHcs2q2R9JVg3RXHVwyXGqoJNOGIeeEOKt7MPHRJm/otj+qRY3zZlT /uG0hTseUcmy8fx3Lfek/SWRQpZnVMpaqnVBDFd/tFo6ieOKWg9glBWlmJJWbav/Po1aro a72pVWDK2Efc5lg5yiL3jzXcYNDpiAaDcFJXvfOyBk0kO8lfqevfPxTcKj1owCfOid8+a1 1+tSatWZIiRo1SJ7r4yWNK0oYl3QRJhYU3GPjdENQ4Z3T5WEjRCQp8gD5x090Q== 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 4ZDC2t2jLQz14BV; Thu, 13 Mar 2025 16:03:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 52DG3Ipa048663; Thu, 13 Mar 2025 16:03:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 52DG3IC3048660; Thu, 13 Mar 2025 16:03:18 GMT (envelope-from git) Date: Thu, 13 Mar 2025 16:03:18 GMT Message-Id: <202503131603.52DG3IC3048660@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 3eb6d4b4a25a - main - mlx5: recalculate tcp checksum for ipv4 hw lro coalesced packet List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3eb6d4b4a25a13b9ea9d825ee44c641b91669d06 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=3eb6d4b4a25a13b9ea9d825ee44c641b91669d06 commit 3eb6d4b4a25a13b9ea9d825ee44c641b91669d06 Author: Konstantin Belousov AuthorDate: 2025-02-08 07:21:55 +0000 Commit: Konstantin Belousov CommitDate: 2025-03-13 16:00:09 +0000 mlx5: recalculate tcp checksum for ipv4 hw lro coalesced packet Reviewed by: Ariel Ehrenberg , Slava Shwartsman Sponsored by: NVidia networking MFC after: 1 week --- sys/dev/mlx5/mlx5_en/mlx5_en_rx.c | 42 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c b/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c index a7d796c57eee..f30cdeae199f 100644 --- a/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c +++ b/sys/dev/mlx5/mlx5_en/mlx5_en_rx.c @@ -27,6 +27,7 @@ #include "opt_ratelimit.h" #include +#include #include #include @@ -128,6 +129,27 @@ mlx5e_post_rx_wqes(struct mlx5e_rq *rq) mlx5_wq_ll_update_db_record(&rq->wq); } +static uint32_t +csum_reduce(uint32_t val) +{ + while (val > 0xffff) + val = (val >> 16) + (val & 0xffff); + return (val); +} + +static u_short +csum_buf(uint32_t val, void *buf, int len) +{ + u_short x; + + MPASS(len % 2 == 0); + for (int i = 0; i < len; i += 2) { + bcopy((char *)buf + i, &x, 2); + val = csum_reduce(val + x); + } + return (val); +} + static void mlx5e_lro_update_hdr(struct mbuf *mb, struct mlx5_cqe64 *cqe) { @@ -139,6 +161,7 @@ mlx5e_lro_update_hdr(struct mbuf *mb, struct mlx5_cqe64 *cqe) struct ip *ip4 = NULL; struct tcphdr *th; uint32_t *ts_ptr; + uint32_t tcp_csum; uint8_t l4_hdr_type; int tcp_ack; @@ -200,17 +223,34 @@ mlx5e_lro_update_hdr(struct mbuf *mb, struct mlx5_cqe64 *cqe) } } if (ip4) { + struct ipovly io; + ip4->ip_ttl = cqe->lro_min_ttl; ip4->ip_len = cpu_to_be16(tot_len); ip4->ip_sum = 0; ip4->ip_sum = in_cksum_skip(mb, (ip4->ip_hl << 2) + ETHER_HDR_LEN, ETHER_HDR_LEN); + + /* TCP checksum: data */ + tcp_csum = cqe->check_sum; + + /* TCP checksum: IP pseudoheader */ + bzero(io.ih_x1, sizeof(io.ih_x1)); + io.ih_pr = IPPROTO_TCP; + io.ih_len = htons(ntohs(ip4->ip_len) - sizeof(*ip4)); + io.ih_src = ip4->ip_src; + io.ih_dst = ip4->ip_dst; + tcp_csum = csum_buf(tcp_csum, &io, sizeof(io)); + + /* TCP checksum: TCP header */ + th->th_sum = 0; + tcp_csum = csum_buf(tcp_csum, th, th->th_off * 4); + th->th_sum = ~tcp_csum & 0xffff; } else { ip6->ip6_hlim = cqe->lro_min_ttl; ip6->ip6_plen = cpu_to_be16(tot_len - sizeof(struct ip6_hdr)); } - /* TODO: handle tcp checksum */ } static uint64_t