Commit 3b023e1b authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Jason Gunthorpe

RDMA/core: Create and destroy counters in the ib_core

Move allocation and destruction of counters under ib_core responsibility

Link: https://lore.kernel.org/r/20200630101855.368895-2-leon@kernel.orgSigned-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 6c01e6b2
...@@ -2687,6 +2687,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops) ...@@ -2687,6 +2687,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
SET_DEVICE_OP(dev_ops, set_vf_link_state); SET_DEVICE_OP(dev_ops, set_vf_link_state);
SET_OBJ_SIZE(dev_ops, ib_ah); 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_cq);
SET_OBJ_SIZE(dev_ops, ib_pd); SET_OBJ_SIZE(dev_ops, ib_pd);
SET_OBJ_SIZE(dev_ops, ib_srq); SET_OBJ_SIZE(dev_ops, ib_srq);
......
...@@ -46,7 +46,9 @@ static int uverbs_free_counters(struct ib_uobject *uobject, ...@@ -46,7 +46,9 @@ static int uverbs_free_counters(struct ib_uobject *uobject,
if (ret) if (ret)
return ret; return ret;
return counters->device->ops.destroy_counters(counters); counters->device->ops.destroy_counters(counters);
kfree(counters);
return 0;
} }
static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)( static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(
...@@ -66,20 +68,19 @@ static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)( ...@@ -66,20 +68,19 @@ static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(
if (!ib_dev->ops.create_counters) if (!ib_dev->ops.create_counters)
return -EOPNOTSUPP; return -EOPNOTSUPP;
counters = ib_dev->ops.create_counters(ib_dev, attrs); counters = rdma_zalloc_drv_obj(ib_dev, ib_counters);
if (IS_ERR(counters)) { if (!counters)
ret = PTR_ERR(counters); return -ENOMEM;
goto err_create_counters;
}
counters->device = ib_dev; counters->device = ib_dev;
counters->uobject = uobj; counters->uobject = uobj;
uobj->object = counters; uobj->object = counters;
atomic_set(&counters->usecnt, 0); atomic_set(&counters->usecnt, 0);
return 0; ret = ib_dev->ops.create_counters(counters, attrs);
if (ret)
kfree(counters);
err_create_counters:
return ret; return ret;
} }
......
...@@ -6455,7 +6455,7 @@ static int mlx5_ib_read_counters(struct ib_counters *counters, ...@@ -6455,7 +6455,7 @@ static int mlx5_ib_read_counters(struct ib_counters *counters,
return ret; return ret;
} }
static int mlx5_ib_destroy_counters(struct ib_counters *counters) static void mlx5_ib_destroy_counters(struct ib_counters *counters)
{ {
struct mlx5_ib_mcounters *mcounters = to_mcounters(counters); struct mlx5_ib_mcounters *mcounters = to_mcounters(counters);
...@@ -6463,24 +6463,15 @@ static int mlx5_ib_destroy_counters(struct ib_counters *counters) ...@@ -6463,24 +6463,15 @@ static int mlx5_ib_destroy_counters(struct ib_counters *counters)
if (mcounters->hw_cntrs_hndl) if (mcounters->hw_cntrs_hndl)
mlx5_fc_destroy(to_mdev(counters->device)->mdev, mlx5_fc_destroy(to_mdev(counters->device)->mdev,
mcounters->hw_cntrs_hndl); mcounters->hw_cntrs_hndl);
kfree(mcounters);
return 0;
} }
static struct ib_counters *mlx5_ib_create_counters(struct ib_device *device, static int mlx5_ib_create_counters(struct ib_counters *counters,
struct uverbs_attr_bundle *attrs) struct uverbs_attr_bundle *attrs)
{ {
struct mlx5_ib_mcounters *mcounters; struct mlx5_ib_mcounters *mcounters = to_mcounters(counters);
mcounters = kzalloc(sizeof(*mcounters), GFP_KERNEL);
if (!mcounters)
return ERR_PTR(-ENOMEM);
mutex_init(&mcounters->mcntrs_mutex); mutex_init(&mcounters->mcntrs_mutex);
return 0;
return &mcounters->ibcntrs;
} }
static void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev) static void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev)
...@@ -6648,6 +6639,7 @@ static const struct ib_device_ops mlx5_ib_dev_ops = { ...@@ -6648,6 +6639,7 @@ static const struct ib_device_ops mlx5_ib_dev_ops = {
.resize_cq = mlx5_ib_resize_cq, .resize_cq = mlx5_ib_resize_cq,
INIT_RDMA_OBJ_SIZE(ib_ah, mlx5_ib_ah, ibah), INIT_RDMA_OBJ_SIZE(ib_ah, mlx5_ib_ah, ibah),
INIT_RDMA_OBJ_SIZE(ib_counters, mlx5_ib_mcounters, ibcntrs),
INIT_RDMA_OBJ_SIZE(ib_cq, mlx5_ib_cq, ibcq), INIT_RDMA_OBJ_SIZE(ib_cq, mlx5_ib_cq, ibcq),
INIT_RDMA_OBJ_SIZE(ib_pd, mlx5_ib_pd, ibpd), INIT_RDMA_OBJ_SIZE(ib_pd, mlx5_ib_pd, ibpd),
INIT_RDMA_OBJ_SIZE(ib_srq, mlx5_ib_srq, ibsrq), INIT_RDMA_OBJ_SIZE(ib_srq, mlx5_ib_srq, ibsrq),
......
...@@ -2540,9 +2540,9 @@ struct ib_device_ops { ...@@ -2540,9 +2540,9 @@ struct ib_device_ops {
struct ib_mr *(*reg_dm_mr)(struct ib_pd *pd, struct ib_dm *dm, struct ib_mr *(*reg_dm_mr)(struct ib_pd *pd, struct ib_dm *dm,
struct ib_dm_mr_attr *attr, struct ib_dm_mr_attr *attr,
struct uverbs_attr_bundle *attrs); struct uverbs_attr_bundle *attrs);
struct ib_counters *(*create_counters)( int (*create_counters)(struct ib_counters *counters,
struct ib_device *device, struct uverbs_attr_bundle *attrs); struct uverbs_attr_bundle *attrs);
int (*destroy_counters)(struct ib_counters *counters); void (*destroy_counters)(struct ib_counters *counters);
int (*read_counters)(struct ib_counters *counters, int (*read_counters)(struct ib_counters *counters,
struct ib_counters_read_attr *counters_read_attr, struct ib_counters_read_attr *counters_read_attr,
struct uverbs_attr_bundle *attrs); struct uverbs_attr_bundle *attrs);
...@@ -2650,6 +2650,7 @@ struct ib_device_ops { ...@@ -2650,6 +2650,7 @@ struct ib_device_ops {
struct uverbs_attr_bundle *attrs); struct uverbs_attr_bundle *attrs);
DECLARE_RDMA_OBJ_SIZE(ib_ah); DECLARE_RDMA_OBJ_SIZE(ib_ah);
DECLARE_RDMA_OBJ_SIZE(ib_counters);
DECLARE_RDMA_OBJ_SIZE(ib_cq); DECLARE_RDMA_OBJ_SIZE(ib_cq);
DECLARE_RDMA_OBJ_SIZE(ib_pd); DECLARE_RDMA_OBJ_SIZE(ib_pd);
DECLARE_RDMA_OBJ_SIZE(ib_srq); DECLARE_RDMA_OBJ_SIZE(ib_srq);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment