git: cd8c576d69d0 - stable/13 - ena: Add reset reason for corrupted RX cdescs

From: Osama Abboud <osamaabb_at_FreeBSD.org>
Date: Thu, 31 Oct 2024 16:00:02 UTC
The branch stable/13 has been updated by osamaabb:

URL: https://cgit.FreeBSD.org/src/commit/?id=cd8c576d69d023af394a459c293cd1e13465920e

commit cd8c576d69d023af394a459c293cd1e13465920e
Author:     Osama Abboud <osamaabb@amazon.com>
AuthorDate: 2024-08-07 06:24:19 +0000
Commit:     Osama Abboud <osamaabb@FreeBSD.org>
CommitDate: 2024-10-31 14:55:19 +0000

    ena: Add reset reason for corrupted RX cdescs
    
    RX completion descriptors may sometimes contain errors due
    to corruption. Upon identifying such a case, the driver will
    trigger a reset with an explicit reset reason
    ENA_REGS_RESET_RX_DESCRIPTOR_MALFORMED.
    
    Approved by: cperciva (mentor)
    Sponsored by: Amazon, Inc.
    
    (cherry picked from commit 4af71159db3cd4a37055b2b3d982ec53703c5c3d)
---
 sys/dev/ena/ena.h          | 2 ++
 sys/dev/ena/ena_datapath.c | 2 ++
 sys/dev/ena/ena_netmap.c   | 2 ++
 sys/dev/ena/ena_sysctl.c   | 2 ++
 4 files changed, 8 insertions(+)

diff --git a/sys/dev/ena/ena.h b/sys/dev/ena/ena.h
index 22c42a9346f7..b747736224d8 100644
--- a/sys/dev/ena/ena.h
+++ b/sys/dev/ena/ena.h
@@ -390,6 +390,7 @@ struct ena_stats_dev {
 	counter_u64_t invalid_state;
 	counter_u64_t missing_intr;
 	counter_u64_t tx_desc_malformed;
+	counter_u64_t rx_desc_malformed;
 };
 
 struct ena_hw_stats {
@@ -550,6 +551,7 @@ static const struct ena_reset_stats_offset resets_to_stats_offset_map[ENA_REGS_R
 	ENA_RESET_STATS_ENTRY(ENA_REGS_RESET_DRIVER_INVALID_STATE, invalid_state),
 	ENA_RESET_STATS_ENTRY(ENA_REGS_RESET_MISS_INTERRUPT, missing_intr),
 	ENA_RESET_STATS_ENTRY(ENA_REGS_RESET_TX_DESCRIPTOR_MALFORMED, tx_desc_malformed),
+	ENA_RESET_STATS_ENTRY(ENA_REGS_RESET_RX_DESCRIPTOR_MALFORMED, rx_desc_malformed),
 };
 
 int	ena_up(struct ena_adapter *adapter);
diff --git a/sys/dev/ena/ena_datapath.c b/sys/dev/ena/ena_datapath.c
index e85d29d7f278..831189006f15 100644
--- a/sys/dev/ena/ena_datapath.c
+++ b/sys/dev/ena/ena_datapath.c
@@ -599,6 +599,8 @@ ena_rx_cleanup(struct ena_ring *rx_ring)
 				counter_u64_add(rx_ring->rx_stats.bad_desc_num,
 				    1);
 				reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS;
+			} else if (rc == ENA_COM_FAULT) {
+				reset_reason = ENA_REGS_RESET_RX_DESCRIPTOR_MALFORMED;
 			} else {
 				counter_u64_add(rx_ring->rx_stats.bad_req_id,
 				    1);
diff --git a/sys/dev/ena/ena_netmap.c b/sys/dev/ena/ena_netmap.c
index fb2c5cb21e6d..54c8269be3b2 100644
--- a/sys/dev/ena/ena_netmap.c
+++ b/sys/dev/ena/ena_netmap.c
@@ -938,6 +938,8 @@ ena_netmap_rx_frame(struct ena_netmap_ctx *ctx)
 		if (rc == ENA_COM_NO_SPACE) {
 			counter_u64_add(ctx->ring->rx_stats.bad_desc_num, 1);
 			reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS;
+		} else if (rc == ENA_COM_FAULT) {
+			reset_reason = ENA_REGS_RESET_RX_DESCRIPTOR_MALFORMED;
 		} else {
 			counter_u64_add(ctx->ring->rx_stats.bad_req_id, 1);
 			reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID;
diff --git a/sys/dev/ena/ena_sysctl.c b/sys/dev/ena/ena_sysctl.c
index 71c25dd5e443..e46e835572fe 100644
--- a/sys/dev/ena/ena_sysctl.c
+++ b/sys/dev/ena/ena_sysctl.c
@@ -296,6 +296,8 @@ ena_sysctl_add_stats(struct ena_adapter *adapter)
 	    &dev_stats->missing_intr, "Missing interrupt count");
 	SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "tx_desc_malformed", CTLFLAG_RD,
 	    &dev_stats->tx_desc_malformed, "TX descriptors malformed count");
+	SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "rx_desc_malformed", CTLFLAG_RD,
+	    &dev_stats->rx_desc_malformed, "RX descriptors malformed count");
 	SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "total_resets", CTLFLAG_RD,
 	    &dev_stats->total_resets, "Total resets count");