Skip to content

Commit da37110

Browse files
PatrisiousHaddadrleon
authored andcommitted
RDMA/core: Add support to optional-counters binding configuration
Whenever a new counter is created, save inside it the user requested configuration for optional-counters binding, for manual configuration it is requested directly by the user and for the automatic configuration it depends on if the automatic binding was enabled with or without optional-counters binding. This argument will later be used by the driver to determine if to bind the optional-counters as well or not when trying to bind this counter to a QP. It indicates that when binding counters to a QP we also want the currently enabled link optional-counters to be bound as well. Signed-off-by: Patrisious Haddad <[email protected]> Reviewed-by: Mark Bloch <[email protected]> Link: https://patch.msgid.link/82f1c357606a16932979ef9a5910122675c74a3a.1741875070.git.leon@kernel.org Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 7e53b31 commit da37110

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

drivers/infiniband/core/counters.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
static int __counter_set_mode(struct rdma_port_counter *port_counter,
1414
enum rdma_nl_counter_mode new_mode,
15-
enum rdma_nl_counter_mask new_mask)
15+
enum rdma_nl_counter_mask new_mask,
16+
bool bind_opcnt)
1617
{
1718
if (new_mode == RDMA_COUNTER_MODE_AUTO) {
1819
if (new_mask & (~ALL_AUTO_MODE_MASKS))
@@ -23,6 +24,7 @@ static int __counter_set_mode(struct rdma_port_counter *port_counter,
2324

2425
port_counter->mode.mode = new_mode;
2526
port_counter->mode.mask = new_mask;
27+
port_counter->mode.bind_opcnt = bind_opcnt;
2628
return 0;
2729
}
2830

@@ -41,6 +43,7 @@ static int __counter_set_mode(struct rdma_port_counter *port_counter,
4143
*/
4244
int rdma_counter_set_auto_mode(struct ib_device *dev, u32 port,
4345
enum rdma_nl_counter_mask mask,
46+
bool bind_opcnt,
4447
struct netlink_ext_ack *extack)
4548
{
4649
struct rdma_port_counter *port_counter;
@@ -59,12 +62,13 @@ int rdma_counter_set_auto_mode(struct ib_device *dev, u32 port,
5962
RDMA_COUNTER_MODE_NONE;
6063

6164
if (port_counter->mode.mode == mode &&
62-
port_counter->mode.mask == mask) {
65+
port_counter->mode.mask == mask &&
66+
port_counter->mode.bind_opcnt == bind_opcnt) {
6367
ret = 0;
6468
goto out;
6569
}
6670

67-
ret = __counter_set_mode(port_counter, mode, mask);
71+
ret = __counter_set_mode(port_counter, mode, mask, bind_opcnt);
6872

6973
out:
7074
mutex_unlock(&port_counter->lock);
@@ -140,7 +144,8 @@ int rdma_counter_modify(struct ib_device *dev, u32 port,
140144

141145
static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port,
142146
struct ib_qp *qp,
143-
enum rdma_nl_counter_mode mode)
147+
enum rdma_nl_counter_mode mode,
148+
bool bind_opcnt)
144149
{
145150
struct rdma_port_counter *port_counter;
146151
struct rdma_counter *counter;
@@ -168,7 +173,7 @@ static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port,
168173
switch (mode) {
169174
case RDMA_COUNTER_MODE_MANUAL:
170175
ret = __counter_set_mode(port_counter, RDMA_COUNTER_MODE_MANUAL,
171-
0);
176+
0, bind_opcnt);
172177
if (ret) {
173178
mutex_unlock(&port_counter->lock);
174179
goto err_mode;
@@ -187,6 +192,7 @@ static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port,
187192
mutex_unlock(&port_counter->lock);
188193

189194
counter->mode.mode = mode;
195+
counter->mode.bind_opcnt = bind_opcnt;
190196
kref_init(&counter->kref);
191197
mutex_init(&counter->lock);
192198

@@ -215,7 +221,8 @@ static void rdma_counter_free(struct rdma_counter *counter)
215221
port_counter->num_counters--;
216222
if (!port_counter->num_counters &&
217223
(port_counter->mode.mode == RDMA_COUNTER_MODE_MANUAL))
218-
__counter_set_mode(port_counter, RDMA_COUNTER_MODE_NONE, 0);
224+
__counter_set_mode(port_counter, RDMA_COUNTER_MODE_NONE, 0,
225+
false);
219226

220227
mutex_unlock(&port_counter->lock);
221228

@@ -347,7 +354,8 @@ int rdma_counter_bind_qp_auto(struct ib_qp *qp, u32 port)
347354
return ret;
348355
}
349356
} else {
350-
counter = alloc_and_bind(dev, port, qp, RDMA_COUNTER_MODE_AUTO);
357+
counter = alloc_and_bind(dev, port, qp, RDMA_COUNTER_MODE_AUTO,
358+
port_counter->mode.bind_opcnt);
351359
if (!counter)
352360
return -ENOMEM;
353361
}
@@ -560,7 +568,7 @@ int rdma_counter_bind_qpn_alloc(struct ib_device *dev, u32 port,
560568
goto err;
561569
}
562570

563-
counter = alloc_and_bind(dev, port, qp, RDMA_COUNTER_MODE_MANUAL);
571+
counter = alloc_and_bind(dev, port, qp, RDMA_COUNTER_MODE_MANUAL, true);
564572
if (!counter) {
565573
ret = -ENOMEM;
566574
goto err;
@@ -615,13 +623,15 @@ int rdma_counter_unbind_qpn(struct ib_device *dev, u32 port,
615623

616624
int rdma_counter_get_mode(struct ib_device *dev, u32 port,
617625
enum rdma_nl_counter_mode *mode,
618-
enum rdma_nl_counter_mask *mask)
626+
enum rdma_nl_counter_mask *mask,
627+
bool *opcnt)
619628
{
620629
struct rdma_port_counter *port_counter;
621630

622631
port_counter = &dev->port_data[port].port_counter;
623632
*mode = port_counter->mode.mode;
624633
*mask = port_counter->mode.mask;
634+
*opcnt = port_counter->mode.bind_opcnt;
625635

626636
return 0;
627637
}

drivers/infiniband/core/nldev.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
171171
[RDMA_NLDEV_ATTR_PARENT_NAME] = { .type = NLA_NUL_STRING },
172172
[RDMA_NLDEV_ATTR_NAME_ASSIGN_TYPE] = { .type = NLA_U8 },
173173
[RDMA_NLDEV_ATTR_EVENT_TYPE] = { .type = NLA_U8 },
174+
[RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED] = { .type = NLA_U8 },
174175
};
175176

176177
static int put_driver_name_print_type(struct sk_buff *msg, const char *name,
@@ -2028,19 +2029,25 @@ static int nldev_stat_set_mode_doit(struct sk_buff *msg,
20282029
struct ib_device *device, u32 port)
20292030
{
20302031
u32 mode, mask = 0, qpn, cntn = 0;
2032+
bool opcnt = false;
20312033
int ret;
20322034

20332035
/* Currently only counter for QP is supported */
20342036
if (!tb[RDMA_NLDEV_ATTR_STAT_RES] ||
20352037
nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_RES]) != RDMA_NLDEV_ATTR_RES_QP)
20362038
return -EINVAL;
20372039

2040+
if (tb[RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED])
2041+
opcnt = !!nla_get_u8(
2042+
tb[RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED]);
2043+
20382044
mode = nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_MODE]);
20392045
if (mode == RDMA_COUNTER_MODE_AUTO) {
20402046
if (tb[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK])
20412047
mask = nla_get_u32(
20422048
tb[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK]);
2043-
return rdma_counter_set_auto_mode(device, port, mask, extack);
2049+
return rdma_counter_set_auto_mode(device, port, mask, opcnt,
2050+
extack);
20442051
}
20452052

20462053
if (!tb[RDMA_NLDEV_ATTR_RES_LQPN])
@@ -2358,6 +2365,7 @@ static int stat_get_doit_qp(struct sk_buff *skb, struct nlmsghdr *nlh,
23582365
struct ib_device *device;
23592366
struct sk_buff *msg;
23602367
u32 index, port;
2368+
bool opcnt;
23612369
int ret;
23622370

23632371
if (tb[RDMA_NLDEV_ATTR_STAT_COUNTER_ID])
@@ -2393,7 +2401,7 @@ static int stat_get_doit_qp(struct sk_buff *skb, struct nlmsghdr *nlh,
23932401
goto err_msg;
23942402
}
23952403

2396-
ret = rdma_counter_get_mode(device, port, &mode, &mask);
2404+
ret = rdma_counter_get_mode(device, port, &mode, &mask, &opcnt);
23972405
if (ret)
23982406
goto err_msg;
23992407

@@ -2410,6 +2418,12 @@ static int stat_get_doit_qp(struct sk_buff *skb, struct nlmsghdr *nlh,
24102418
goto err_msg;
24112419
}
24122420

2421+
if ((mode == RDMA_COUNTER_MODE_AUTO) &&
2422+
nla_put_u8(msg, RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED, opcnt)) {
2423+
ret = -EMSGSIZE;
2424+
goto err_msg;
2425+
}
2426+
24132427
nlmsg_end(msg, nlh);
24142428
ib_device_put(device);
24152429
return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);

include/rdma/rdma_counter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct rdma_counter_mode {
2323
enum rdma_nl_counter_mode mode;
2424
enum rdma_nl_counter_mask mask;
2525
struct auto_mode_param param;
26+
bool bind_opcnt;
2627
};
2728

2829
struct rdma_port_counter {
@@ -47,6 +48,7 @@ void rdma_counter_init(struct ib_device *dev);
4748
void rdma_counter_release(struct ib_device *dev);
4849
int rdma_counter_set_auto_mode(struct ib_device *dev, u32 port,
4950
enum rdma_nl_counter_mask mask,
51+
bool bind_opcnt,
5052
struct netlink_ext_ack *extack);
5153
int rdma_counter_bind_qp_auto(struct ib_qp *qp, u32 port);
5254
int rdma_counter_unbind_qp(struct ib_qp *qp, bool force);
@@ -61,7 +63,8 @@ int rdma_counter_unbind_qpn(struct ib_device *dev, u32 port,
6163
u32 qp_num, u32 counter_id);
6264
int rdma_counter_get_mode(struct ib_device *dev, u32 port,
6365
enum rdma_nl_counter_mode *mode,
64-
enum rdma_nl_counter_mask *mask);
66+
enum rdma_nl_counter_mask *mask,
67+
bool *opcnt);
6568

6669
int rdma_counter_modify(struct ib_device *dev, u32 port,
6770
unsigned int index, bool enable);

include/uapi/rdma/rdma_netlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,8 @@ enum rdma_nldev_attr {
580580
RDMA_NLDEV_ATTR_EVENT_TYPE, /* u8 */
581581

582582
RDMA_NLDEV_SYS_ATTR_MONITOR_MODE, /* u8 */
583+
584+
RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED, /* u8 */
583585
/*
584586
* Always the end
585587
*/

0 commit comments

Comments
 (0)