Skip to contentSkip to conversation

RDMA: Move ib_dm allocation to be under ib_core responsibility

PATCH New Leon Romanovsky 1 participant 1 message Jul 6, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA: Move ib_dm allocation to be under ib_core responsibility

From: Leon Romanovsky <[email protected]>

Convert struct ib_dm to general allocation/release scheme.

---
 drivers/infiniband/core/device.c              |  1 +
 drivers/infiniband/core/uverbs_std_types_dm.c | 11 ++--
 drivers/infiniband/hw/mlx5/main.c             | 59 +++++++------------
 drivers/infiniband/hw/mlx5/mlx5_ib.h          |  9 ++-
 include/rdma/ib_verbs.h                       | 10 ++--
 5 files changed, 37 insertions(+), 53 deletions(-)
drivers/infiniband/core/device.c +1 -0
index cb61542af03f..5685acfd55fc 100644
@@ -2689,6 +2689,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
 	SET_OBJ_SIZE(dev_ops, ib_ah);
 	SET_OBJ_SIZE(dev_ops, ib_counters);
 	SET_OBJ_SIZE(dev_ops, ib_cq);
+	SET_OBJ_SIZE(dev_ops, ib_dm);
 	SET_OBJ_SIZE(dev_ops, ib_mw);
 	SET_OBJ_SIZE(dev_ops, ib_pd);
 	SET_OBJ_SIZE(dev_ops, ib_srq);
drivers/infiniband/core/uverbs_std_types_dm.c +6 -5
index d5a1de33c2c9..e73c9ac3d138 100644
@@ -45,7 +45,8 @@ static int uverbs_free_dm(struct ib_uobject *uobject,
 	if (ret)
 		return ret;
 
-	return dm->device->ops.dealloc_dm(dm, attrs);
+	dm->device->ops.dealloc_dm(dm, attrs);
+	return 0;
 }
 
 static int UVERBS_HANDLER(UVERBS_METHOD_DM_ALLOC)(
@@ -72,9 +73,9 @@ static int UVERBS_HANDLER(UVERBS_METHOD_DM_ALLOC)(
 	if (ret)
 		return ret;
 
-	dm = ib_dev->ops.alloc_dm(ib_dev, attrs->context, &attr, attrs);
-	if (IS_ERR(dm))
-		return PTR_ERR(dm);
+	dm = rdma_zalloc_drv_obj(ib_dev, ib_dm);
+	if (!dm)
+		return -ENOMEM;
 
 	dm->device  = ib_dev;
 	dm->length  = attr.length;
@@ -83,7 +84,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_DM_ALLOC)(
 
 	uobj->object = dm;
 
-	return 0;
+	return ib_dev->ops.alloc_dm(dm, attrs->context, &attr, attrs);
 }
 
 DECLARE_UVERBS_NAMED_METHOD(
drivers/infiniband/hw/mlx5/main.c +21 -38

106 lines not on this page · raw message

drivers/infiniband/hw/mlx5/mlx5_ib.h +4 -5
index 3e8116544c47..8f2ea4d196ba 100644
@@ -1249,11 +1249,10 @@ struct ib_rwq_ind_table *mlx5_ib_create_rwq_ind_table(struct ib_device *device,
 						      struct ib_rwq_ind_table_init_attr *init_attr,
 						      struct ib_udata *udata);
 int mlx5_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
-struct ib_dm *mlx5_ib_alloc_dm(struct ib_device *ibdev,
-			       struct ib_ucontext *context,
-			       struct ib_dm_alloc_attr *attr,
-			       struct uverbs_attr_bundle *attrs);
-int mlx5_ib_dealloc_dm(struct ib_dm *ibdm, struct uverbs_attr_bundle *attrs);
+int mlx5_ib_alloc_dm(struct ib_dm *dm, struct ib_ucontext *context,
+		     struct ib_dm_alloc_attr *attr,
+		     struct uverbs_attr_bundle *attrs);
+void mlx5_ib_dealloc_dm(struct ib_dm *ibdm, struct uverbs_attr_bundle *attrs);
 struct ib_mr *mlx5_ib_reg_dm_mr(struct ib_pd *pd, struct ib_dm *dm,
 				struct ib_dm_mr_attr *attr,
 				struct uverbs_attr_bundle *attrs);
include/rdma/ib_verbs.h +5 -5
index a7f68e005fde..6e83353eb60b 100644
@@ -2531,11 +2531,10 @@ struct ib_device_ops {
 		struct ib_rwq_ind_table_init_attr *init_attr,
 		struct ib_udata *udata);
 	int (*destroy_rwq_ind_table)(struct ib_rwq_ind_table *wq_ind_table);
-	struct ib_dm *(*alloc_dm)(struct ib_device *device,
-				  struct ib_ucontext *context,
-				  struct ib_dm_alloc_attr *attr,
-				  struct uverbs_attr_bundle *attrs);
-	int (*dealloc_dm)(struct ib_dm *dm, struct uverbs_attr_bundle *attrs);
+	int (*alloc_dm)(struct ib_dm *ib_dm, struct ib_ucontext *context,
+			struct ib_dm_alloc_attr *attr,
+			struct uverbs_attr_bundle *attrs);
+	void (*dealloc_dm)(struct ib_dm *dm, struct uverbs_attr_bundle *attrs);
 	struct ib_mr *(*reg_dm_mr)(struct ib_pd *pd, struct ib_dm *dm,
 				   struct ib_dm_mr_attr *attr,
 				   struct uverbs_attr_bundle *attrs);
@@ -2651,6 +2650,7 @@ struct ib_device_ops {
 	DECLARE_RDMA_OBJ_SIZE(ib_ah);
 	DECLARE_RDMA_OBJ_SIZE(ib_counters);
 	DECLARE_RDMA_OBJ_SIZE(ib_cq);
+	DECLARE_RDMA_OBJ_SIZE(ib_dm);
 	DECLARE_RDMA_OBJ_SIZE(ib_mw);
 	DECLARE_RDMA_OBJ_SIZE(ib_pd);
 	DECLARE_RDMA_OBJ_SIZE(ib_srq);
Signature · 1 line
2.26.2