git: 4af71159db3c - main - ena: Add reset reason for corrupted RX cdescs

From: Osama Abboud <osamaabb_at_FreeBSD.org>
Date: Tue, 15 Oct 2024 17:43:07 UTC
The branch main has been updated by osamaabb:

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

commit 4af71159db3cd4a37055b2b3d982ec53703c5c3d
Author:     Osama Abboud <osamaabb@amazon.com>
AuthorDate: 2024-08-07 06:24:19 +0000
Commit:     Osama Abboud <osamaabb@FreeBSD.org>
CommitDate: 2024-10-15 17:38:31 +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)
    MFC after: 2 weeks
    Sponsored by: Amazon, Inc.
---
 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 c63a8914f9c2..6cbe46cead3e 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 618d25a07f67..0666d7deb827 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 f6f9f68e6334..79c167221a0f 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");