git: b0b932804bf6 - stable/14 - mlx5: Fix handling of port_module_event

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sat, 30 Nov 2024 00:41:30 UTC
The branch stable/14 has been updated by kib:

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

commit b0b932804bf6022646067e66ce45df7f2f51f3ab
Author:     Ariel Ehrenberg <aehrenberg@nvidia.com>
AuthorDate: 2024-10-31 09:18:26 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-11-30 00:34:54 +0000

    mlx5: Fix handling of port_module_event
    
    (cherry picked from commit 253a1fa16b98ac5f73f0820cfdd4f5ad7378757a)
---
 sys/dev/mlx5/driver.h            |  3 ++-
 sys/dev/mlx5/mlx5_core/mlx5_eq.c | 10 +++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/sys/dev/mlx5/driver.h b/sys/dev/mlx5/driver.h
index 6ebe4171a503..e1c71b8baa1a 100644
--- a/sys/dev/mlx5/driver.h
+++ b/sys/dev/mlx5/driver.h
@@ -721,7 +721,8 @@ struct mlx5_core_dev {
 	u32			vsc_addr;
 	u32			issi;
 	struct mlx5_special_contexts special_contexts;
-	unsigned int module_status[MLX5_MAX_PORTS];
+	unsigned int module_status;
+	unsigned int module_num;
 	struct mlx5_flow_root_namespace *root_ns;
 	struct mlx5_flow_root_namespace *fdb_root_ns;
 	struct mlx5_flow_root_namespace *esw_egress_root_ns;
diff --git a/sys/dev/mlx5/mlx5_core/mlx5_eq.c b/sys/dev/mlx5/mlx5_core/mlx5_eq.c
index 2d5b53b6482a..e7f282ea576b 100644
--- a/sys/dev/mlx5/mlx5_core/mlx5_eq.c
+++ b/sys/dev/mlx5/mlx5_core/mlx5_eq.c
@@ -679,9 +679,9 @@ static const char *mlx5_port_module_event_error_type_to_string(u8 error_type)
 
 unsigned int mlx5_query_module_status(struct mlx5_core_dev *dev, int module_num)
 {
-	if (module_num < 0 || module_num >= MLX5_MAX_PORTS)
-		return 0;		/* undefined */
-	return dev->module_status[module_num];
+	if (module_num != dev->module_num)
+		return 0;		/* module num doesn't equal to what FW reported */
+	return dev->module_status;
 }
 
 static void mlx5_port_module_event(struct mlx5_core_dev *dev,
@@ -729,8 +729,8 @@ static void mlx5_port_module_event(struct mlx5_core_dev *dev,
 		    "Module %u, unknown status %d\n", module_num, module_status);
 	}
 	/* store module status */
-	if (module_num < MLX5_MAX_PORTS)
-		dev->module_status[module_num] = module_status;
+	dev->module_status = module_status;
+	dev->module_num = module_num;
 }
 
 static void mlx5_port_general_notification_event(struct mlx5_core_dev *dev,