From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id F29844554D; Tue, 2 Jul 2024 16:48:20 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AFF0142D27; Tue, 2 Jul 2024 16:47:04 +0200 (CEST) Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) by mails.dpdk.org (Postfix) with ESMTP id B26AB427C0 for ; Tue, 2 Jul 2024 16:47:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1719931624; x=1751467624; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=lhLkfPZm13jqu9ayGixN3/tcWpy8fqKHKiKVQP3Lae4=; b=CEMhjJ1Aanr8gwDkmS/L5Kq+j0rgs8f375AGjBgDREvGwYEHU8HqL45x T1uINjJ7EKwuhMHMHS1q0Qq/ROk05/N4e4thpBhbq42LjfqI+RO+A6H2I k0P4tfub3K62vdJBw1akebZjF7E+6BKo9yLLS0heuO+ubyIiw5qJiJPLG s=; X-IronPort-AV: E=Sophos;i="6.09,178,1716249600"; d="scan'208";a="215615517" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2024 14:47:04 +0000 Received: from EX19MTAEUC002.ant.amazon.com [10.0.10.100:16449] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.12.198:2525] with esmtp (Farcaster) id df5394b9-43b0-408e-ab1b-ce821b396fd0; Tue, 2 Jul 2024 14:47:02 +0000 (UTC) X-Farcaster-Flow-ID: df5394b9-43b0-408e-ab1b-ce821b396fd0 Received: from EX19D007EUA001.ant.amazon.com (10.252.50.133) by EX19MTAEUC002.ant.amazon.com (10.252.51.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Tue, 2 Jul 2024 14:47:01 +0000 Received: from EX19MTAUWB001.ant.amazon.com (10.250.64.248) by EX19D007EUA001.ant.amazon.com (10.252.50.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Tue, 2 Jul 2024 14:47:00 +0000 Received: from HFA15-CG15235BS.amazon.com (10.85.143.173) by mail-relay.amazon.com (10.250.64.254) with Microsoft SMTP Server id 15.2.1258.34 via Frontend Transport; Tue, 2 Jul 2024 14:46:59 +0000 From: To: CC: , Shai Brandes Subject: [PATCH 14/15] net/ena: rework Rx checksum inspection Date: Tue, 2 Jul 2024 17:46:25 +0300 Message-ID: <20240702144626.14545-15-shaibran@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240702144626.14545-1-shaibran@amazon.com> References: <20240702144626.14545-1-shaibran@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Shai Brandes This restructure is a simplification of the Rx checksum inspection logic in ena_rx_mbuf_prepare. Its purpose is to improve readability and maintainability by consolidating conditions. Signed-off-by: Shai Brandes --- doc/guides/rel_notes/release_24_07.rst | 2 + drivers/net/ena/ena_ethdev.c | 66 +++++++++++++++----------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/doc/guides/rel_notes/release_24_07.rst b/doc/guides/rel_notes/release_24_07.rst index ec960d93cc..d2253999fa 100644 --- a/doc/guides/rel_notes/release_24_07.rst +++ b/doc/guides/rel_notes/release_24_07.rst @@ -81,6 +81,8 @@ New Features * Removed an obsolete workaround for a false L4 bad Rx checksum indication. * Fixed an invalid return value check. * Fixed Rx chcecksum inspection to check only TCP/UDP packets. + * Reworked the Rx checksum inspection routine to improve + readability and maintainability. * **Update Tap PMD driver.** diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c index a18c94df28..feb229c5ec 100644 --- a/drivers/net/ena/ena_ethdev.c +++ b/drivers/net/ena/ena_ethdev.c @@ -53,8 +53,6 @@ */ #define ENA_CLEANUP_BUF_THRESH 256 -#define ENA_PTYPE_HAS_HASH (RTE_PTYPE_L4_TCP | RTE_PTYPE_L4_UDP) - struct ena_stats { char name[ETH_GSTRING_LEN]; int stat_offset; @@ -645,19 +643,14 @@ static inline void ena_trigger_reset(struct ena_adapter *adapter, static inline void ena_rx_mbuf_prepare(struct ena_ring *rx_ring, struct rte_mbuf *mbuf, - struct ena_com_rx_ctx *ena_rx_ctx, - bool fill_hash) + struct ena_com_rx_ctx *ena_rx_ctx) { struct ena_stats_rx *rx_stats = &rx_ring->rx_stats; uint64_t ol_flags = 0; uint32_t packet_type = 0; - if (ena_rx_ctx->l4_proto == ENA_ETH_IO_L4_PROTO_TCP) - packet_type |= RTE_PTYPE_L4_TCP; - else if (ena_rx_ctx->l4_proto == ENA_ETH_IO_L4_PROTO_UDP) - packet_type |= RTE_PTYPE_L4_UDP; - - if (ena_rx_ctx->l3_proto == ENA_ETH_IO_L3_PROTO_IPV4) { + switch (ena_rx_ctx->l3_proto) { + case ENA_ETH_IO_L3_PROTO_IPV4: packet_type |= RTE_PTYPE_L3_IPV4; if (unlikely(ena_rx_ctx->l3_csum_err)) { ++rx_stats->l3_csum_bad; @@ -665,27 +658,45 @@ static inline void ena_rx_mbuf_prepare(struct ena_ring *rx_ring, } else { ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD; } - } else if (ena_rx_ctx->l3_proto == ENA_ETH_IO_L3_PROTO_IPV6) { + break; + case ENA_ETH_IO_L3_PROTO_IPV6: packet_type |= RTE_PTYPE_L3_IPV6; + break; + default: + break; } - if (!ena_rx_ctx->l4_csum_checked || ena_rx_ctx->frag || - !(packet_type & (RTE_PTYPE_L4_TCP | RTE_PTYPE_L4_UDP))) { - ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_UNKNOWN; - } else { - if (unlikely(ena_rx_ctx->l4_csum_err)) { - ++rx_stats->l4_csum_bad; - ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD; + switch (ena_rx_ctx->l4_proto) { + case ENA_ETH_IO_L4_PROTO_TCP: + packet_type |= RTE_PTYPE_L4_TCP; + break; + case ENA_ETH_IO_L4_PROTO_UDP: + packet_type |= RTE_PTYPE_L4_UDP; + break; + default: + break; + } + + /* L4 csum is relevant only for TCP/UDP packets */ + if ((packet_type & (RTE_PTYPE_L4_TCP | RTE_PTYPE_L4_UDP)) && !ena_rx_ctx->frag) { + if (ena_rx_ctx->l4_csum_checked) { + if (likely(!ena_rx_ctx->l4_csum_err)) { + ++rx_stats->l4_csum_good; + ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD; + } else { + ++rx_stats->l4_csum_bad; + ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD; + } } else { - ++rx_stats->l4_csum_good; - ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD; + ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_UNKNOWN; } - } - if (fill_hash && - likely((packet_type & ENA_PTYPE_HAS_HASH) && !ena_rx_ctx->frag)) { - ol_flags |= RTE_MBUF_F_RX_RSS_HASH; - mbuf->hash.rss = ena_rx_ctx->hash; + if (rx_ring->offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH) { + ol_flags |= RTE_MBUF_F_RX_RSS_HASH; + mbuf->hash.rss = ena_rx_ctx->hash; + } + } else { + ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_UNKNOWN; } mbuf->ol_flags = ol_flags; @@ -2765,7 +2776,6 @@ static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t completed; struct ena_com_rx_ctx ena_rx_ctx; int i, rc = 0; - bool fill_hash; #ifdef RTE_ETHDEV_DEBUG_RX /* Check adapter state */ @@ -2776,8 +2786,6 @@ static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, } #endif - fill_hash = rx_ring->offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH; - descs_in_use = rx_ring->ring_size - ena_com_free_q_entries(rx_ring->ena_com_io_sq) - 1; nb_pkts = RTE_MIN(descs_in_use, nb_pkts); @@ -2823,7 +2831,7 @@ static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, } /* fill mbuf attributes if any */ - ena_rx_mbuf_prepare(rx_ring, mbuf, &ena_rx_ctx, fill_hash); + ena_rx_mbuf_prepare(rx_ring, mbuf, &ena_rx_ctx); if (unlikely(mbuf->ol_flags & (RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_BAD))) -- 2.17.1