Skip to content

Commit 7e53b31

Browse files
PatrisiousHaddadrleon
authored andcommitted
RDMA/core: Create and destroy rdma_counter using rdma_zalloc_drv_obj()
Change rdma_counter allocation to use rdma_zalloc_drv_obj() instead of, explicitly allocating at core, in order to be contained inside driver specific structures. Adjust all drivers that use it to have their containing structure, and add driver specific initialization operation. This change is needed to allow upcoming patches to implement optional-counters binding whereas inside each driver specific counter struct his bound optional-counters will be maintained. Signed-off-by: Patrisious Haddad <[email protected]> Reviewed-by: Mark Bloch <[email protected]> Link: https://patch.msgid.link/a5a484f421fc2e5595158e61a354fba43272b02d.1741875070.git.leon@kernel.org Signed-off-by: Leon Romanovsky <[email protected]>
1 parent d375db4 commit 7e53b31

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

drivers/infiniband/core/counters.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,15 @@ static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port,
149149
if (!dev->ops.counter_dealloc || !dev->ops.counter_alloc_stats)
150150
return NULL;
151151

152-
counter = kzalloc(sizeof(*counter), GFP_KERNEL);
152+
counter = rdma_zalloc_drv_obj(dev, rdma_counter);
153153
if (!counter)
154154
return NULL;
155155

156156
counter->device = dev;
157157
counter->port = port;
158158

159+
dev->ops.counter_init(counter);
160+
159161
rdma_restrack_new(&counter->res, RDMA_RESTRACK_COUNTER);
160162
counter->stats = dev->ops.counter_alloc_stats(counter);
161163
if (!counter->stats)

drivers/infiniband/core/device.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
26832683
SET_DEVICE_OP(dev_ops, counter_alloc_stats);
26842684
SET_DEVICE_OP(dev_ops, counter_bind_qp);
26852685
SET_DEVICE_OP(dev_ops, counter_dealloc);
2686+
SET_DEVICE_OP(dev_ops, counter_init);
26862687
SET_DEVICE_OP(dev_ops, counter_unbind_qp);
26872688
SET_DEVICE_OP(dev_ops, counter_update_stats);
26882689
SET_DEVICE_OP(dev_ops, create_ah);
@@ -2797,6 +2798,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
27972798
SET_OBJ_SIZE(dev_ops, ib_srq);
27982799
SET_OBJ_SIZE(dev_ops, ib_ucontext);
27992800
SET_OBJ_SIZE(dev_ops, ib_xrcd);
2801+
SET_OBJ_SIZE(dev_ops, rdma_counter);
28002802
}
28012803
EXPORT_SYMBOL(ib_set_device_ops);
28022804

drivers/infiniband/hw/mlx5/counters.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,8 @@ static int mlx5_ib_modify_stat(struct ib_device *device, u32 port,
11051105
return 0;
11061106
}
11071107

1108+
static void mlx5_ib_counter_init(struct rdma_counter *counter) {}
1109+
11081110
static const struct ib_device_ops hw_stats_ops = {
11091111
.alloc_hw_port_stats = mlx5_ib_alloc_hw_port_stats,
11101112
.get_hw_stats = mlx5_ib_get_hw_stats,
@@ -1115,6 +1117,9 @@ static const struct ib_device_ops hw_stats_ops = {
11151117
.counter_update_stats = mlx5_ib_counter_update_stats,
11161118
.modify_hw_stat = IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS) ?
11171119
mlx5_ib_modify_stat : NULL,
1120+
.counter_init = mlx5_ib_counter_init,
1121+
1122+
INIT_RDMA_OBJ_SIZE(rdma_counter, mlx5_rdma_counter, rdma_counter),
11181123
};
11191124

11201125
static const struct ib_device_ops hw_switchdev_vport_op = {
@@ -1129,6 +1134,9 @@ static const struct ib_device_ops hw_switchdev_stats_ops = {
11291134
.counter_dealloc = mlx5_ib_counter_dealloc,
11301135
.counter_alloc_stats = mlx5_ib_counter_alloc_stats,
11311136
.counter_update_stats = mlx5_ib_counter_update_stats,
1137+
.counter_init = mlx5_ib_counter_init,
1138+
1139+
INIT_RDMA_OBJ_SIZE(rdma_counter, mlx5_rdma_counter, rdma_counter),
11321140
};
11331141

11341142
static const struct ib_device_ops counters_ops = {

drivers/infiniband/hw/mlx5/counters.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88

99
#include "mlx5_ib.h"
1010

11+
12+
struct mlx5_rdma_counter {
13+
struct rdma_counter rdma_counter;
14+
};
15+
16+
static inline struct mlx5_rdma_counter *
17+
to_mcounter(struct rdma_counter *counter)
18+
{
19+
return container_of(counter, struct mlx5_rdma_counter, rdma_counter);
20+
}
21+
1122
int mlx5_ib_counters_init(struct mlx5_ib_dev *dev);
1223
void mlx5_ib_counters_cleanup(struct mlx5_ib_dev *dev);
1324
void mlx5_ib_counters_clear_description(struct ib_counters *counters);

include/rdma/ib_verbs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,6 +2665,11 @@ struct ib_device_ops {
26652665
*/
26662666
int (*counter_update_stats)(struct rdma_counter *counter);
26672667

2668+
/**
2669+
* counter_init - Initialize the driver specific rdma counter struct.
2670+
*/
2671+
void (*counter_init)(struct rdma_counter *counter);
2672+
26682673
/**
26692674
* Allows rdma drivers to add their own restrack attributes
26702675
* dumped via 'rdma stat' iproute2 command.
@@ -2716,6 +2721,7 @@ struct ib_device_ops {
27162721
DECLARE_RDMA_OBJ_SIZE(ib_srq);
27172722
DECLARE_RDMA_OBJ_SIZE(ib_ucontext);
27182723
DECLARE_RDMA_OBJ_SIZE(ib_xrcd);
2724+
DECLARE_RDMA_OBJ_SIZE(rdma_counter);
27192725
};
27202726

27212727
struct ib_core_device {

0 commit comments

Comments
 (0)