git: bfe14bfeb8dc - main - mlx5: mark completion EQs as a shared resource for DEVX uids

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 07 Jul 2026 11:30:04 UTC
The branch main has been updated by kib:

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

commit bfe14bfeb8dcefc606bdf76c40987467bbd36d92
Author:     Ariel Ehrenberg <aehrenberg@nvidia.com>
AuthorDate: 2026-06-04 15:46:17 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-07-07 11:24:48 +0000

    mlx5: mark completion EQs as a shared resource for DEVX uids
    
    A firmware object owned by a DEVX uid may only reference resources owned
    by the same uid or ones explicitly marked as shared.  Completion EQs
    were created with uid 0, so a CQ owned by a DEVX uid could not attach to
    its EQ and CREATE_CQ failed with "bad resource".
    
    Create completion EQs with MLX5_SHARED_RESOURCE_UID on devices that
    support user contexts, so uid-owned CQs can use them.
    
    The code follows the Linux commit d2c8a1554c10d5e0443b1f97f480d7dacd55cf55
    ("IB/mlx5: Enable UAR to have DevX UID").
    
    Reviewed by:    kib
    Tested by:      Wafa Hamzah <wafah@nvidia.com>
    Sponsored by:   Nvidia networking
    MFC after:      1 month
---
 sys/dev/mlx5/mlx5_core/mlx5_eq.c | 8 ++++++++
 sys/dev/mlx5/mlx5_ifc.h          | 8 +++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/sys/dev/mlx5/mlx5_core/mlx5_eq.c b/sys/dev/mlx5/mlx5_core/mlx5_eq.c
index f564b88c48b4..5279d71e3e86 100644
--- a/sys/dev/mlx5/mlx5_core/mlx5_eq.c
+++ b/sys/dev/mlx5/mlx5_core/mlx5_eq.c
@@ -487,6 +487,14 @@ int mlx5_create_map_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq, u8 vecidx,
 	mlx5_fill_page_array(&eq->buf, pas);
 
 	MLX5_SET(create_eq_in, in, opcode, MLX5_CMD_OP_CREATE_EQ);
+	/*
+	 * Completion EQs (no event mask) must be marked as a shared resource
+	 * when the device supports user contexts; otherwise CQs owned by a
+	 * DEVX uid cannot attach to them and CREATE_CQ fails with a firmware
+	 * "bad resource" error.
+	 */
+	if (mask == 0 && MLX5_CAP_GEN(dev, log_max_uctx))
+		MLX5_SET(create_eq_in, in, uid, MLX5_SHARED_RESOURCE_UID);
 	MLX5_SET64(create_eq_in, in, event_bitmask, mask);
 
 	eqc = MLX5_ADDR_OF(create_eq_in, in, eq_context_entry);
diff --git a/sys/dev/mlx5/mlx5_ifc.h b/sys/dev/mlx5/mlx5_ifc.h
index 0a3bb9b38568..952f51d3c3f7 100644
--- a/sys/dev/mlx5/mlx5_ifc.h
+++ b/sys/dev/mlx5/mlx5_ifc.h
@@ -26,6 +26,12 @@
 #ifndef MLX5_IFC_H
 #define MLX5_IFC_H
 
+/*
+ * Special UID that marks a resource (e.g. an EQ) as shared, so that
+ * objects owned by a user context (DEVX uid) may reference it.
+ */
+#define	MLX5_SHARED_RESOURCE_UID	0xffff
+
 #include <dev/mlx5/mlx5_fpga/mlx5_ifc_fpga.h>
 
 enum {
@@ -8317,7 +8323,7 @@ struct mlx5_ifc_create_eq_out_bits {
 
 struct mlx5_ifc_create_eq_in_bits {
 	u8         opcode[0x10];
-	u8         reserved_0[0x10];
+	u8         uid[0x10];
 
 	u8         reserved_1[0x10];
 	u8         op_mod[0x10];