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.
Unified · Split
| @@ -12,7 +12,8 @@ · 11 unmodified lines | ||
| 12 | 12 | |
| 13 | 13 | static int __counter_set_mode(struct rdma_port_counter *port_counter, |
| 14 | 14 | 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) | |
| 16 | 17 | { |
| 17 | 18 | if (new_mode == RDMA_COUNTER_MODE_AUTO) { |
| 18 | 19 | if (new_mask & (~ALL_AUTO_MODE_MASKS)) |
| @@ -23,6 +24,7 @@ static int __counter_set_mode(struct rdma_port_counter *port_counter, · 4 unmodified lines | ||
| 23 | 24 | |
| 24 | 25 | port_counter->mode.mode = new_mode; |
| 25 | 26 | port_counter->mode.mask = new_mask; |
| 27 | + port_counter->mode.bind_opcnt = bind_opcnt; | |
| 26 | 28 | return 0; |
| 27 | 29 | } |
| 28 | 30 | |
| @@ -41,6 +43,7 @@ static int __counter_set_mode(struct rdma_port_counter *port_counter, · 12 unmodified lines | ||
| 41 | 43 | */ |
| 42 | 44 | int rdma_counter_set_auto_mode(struct ib_device *dev, u32 port, |
| 43 | 45 | enum rdma_nl_counter_mask mask, |
| 46 | + bool bind_opcnt, | |
| 44 | 47 | struct netlink_ext_ack *extack) |
| 45 | 48 | { |
| 46 | 49 | struct rdma_port_counter *port_counter; |
| @@ -59,12 +62,13 @@ int rdma_counter_set_auto_mode(struct ib_device *dev, u32 port, · 12 unmodified lines | ||
| 59 | 62 | RDMA_COUNTER_MODE_NONE; |
| 60 | 63 | |
| 61 | 64 | 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) { | |
| 63 | 67 | ret = 0; |
| 64 | 68 | goto out; |
| 65 | 69 | } |
| 66 | 70 | |
| 67 | − ret = __counter_set_mode(port_counter, mode, mask); | |
| 71 | + ret = __counter_set_mode(port_counter, mode, mask, bind_opcnt); | |
| 68 | 72 | |
| 69 | 73 | out: |
| 70 | 74 | mutex_unlock(&port_counter->lock); |
| @@ -140,7 +144,8 @@ out: · 69 unmodified lines | ||
| 140 | 144 | |
| 141 | 145 | static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port, |
| 142 | 146 | struct ib_qp *qp, |
| 143 | − enum rdma_nl_counter_mode mode) | |
| 147 | + enum rdma_nl_counter_mode mode, | |
| 148 | + bool bind_opcnt) | |
| 144 | 149 | { |
| 145 | 150 | struct rdma_port_counter *port_counter; |
| 146 | 151 | struct rdma_counter *counter; |
| @@ -168,7 +173,7 @@ static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port, · 21 unmodified lines | ||
| 168 | 173 | switch (mode) { |
| 169 | 174 | case RDMA_COUNTER_MODE_MANUAL: |
| 170 | 175 | ret = __counter_set_mode(port_counter, RDMA_COUNTER_MODE_MANUAL, |
| 171 | − 0); | |
| 176 | + 0, bind_opcnt); | |
| 172 | 177 | if (ret) { |
| 173 | 178 | mutex_unlock(&port_counter->lock); |
| 174 | 179 | goto err_mode; |
| @@ -187,6 +192,7 @@ static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port, · 12 unmodified lines | ||
| 187 | 192 | mutex_unlock(&port_counter->lock); |
| 188 | 193 | |
| 189 | 194 | counter->mode.mode = mode; |
| 195 | + counter->mode.bind_opcnt = bind_opcnt; | |
| 190 | 196 | kref_init(&counter->kref); |
| 191 | 197 | mutex_init(&counter->lock); |
| 192 | 198 | |
| @@ -215,7 +221,8 @@ static void rdma_counter_free(struct rdma_counter *counter) · 22 unmodified lines | ||
| 215 | 221 | port_counter->num_counters--; |
| 216 | 222 | if (!port_counter->num_counters && |
| 217 | 223 | (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); | |
| 219 | 226 | |
| 220 | 227 | mutex_unlock(&port_counter->lock); |
| 221 | 228 | |
| @@ -347,7 +354,8 @@ int rdma_counter_bind_qp_auto(struct ib_qp *qp, u32 port) · 125 unmodified lines | ||
| 347 | 354 | return ret; |
| 348 | 355 | } |
| 349 | 356 | } 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); | |
| 351 | 359 | if (!counter) |
| 352 | 360 | return -ENOMEM; |
| 353 | 361 | } |
| @@ -560,7 +568,7 @@ int rdma_counter_bind_qpn_alloc(struct ib_device *dev, u32 port, · 206 unmodified lines | ||
| 560 | 568 | goto err; |
| 561 | 569 | } |
| 562 | 570 | |
| 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); | |
| 564 | 572 | if (!counter) { |
| 565 | 573 | ret = -ENOMEM; |
| 566 | 574 | goto err; |
| @@ -615,13 +623,15 @@ out: · 48 unmodified lines | ||
| 615 | 623 | |
| 616 | 624 | int rdma_counter_get_mode(struct ib_device *dev, u32 port, |
| 617 | 625 | enum rdma_nl_counter_mode *mode, |
| 618 | − enum rdma_nl_counter_mask *mask) | |
| 626 | + enum rdma_nl_counter_mask *mask, | |
| 627 | + bool *opcnt) | |
| 619 | 628 | { |
| 620 | 629 | struct rdma_port_counter *port_counter; |
| 621 | 630 | |
| 622 | 631 | port_counter = &dev->port_data[port].port_counter; |
| 623 | 632 | *mode = port_counter->mode.mode; |
| 624 | 633 | *mask = port_counter->mode.mask; |
| 634 | + *opcnt = port_counter->mode.bind_opcnt; | |
| 625 | 635 | |
| 626 | 636 | return 0; |
| 627 | 637 | } |
| @@ -171,6 +171,7 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = { · 170 unmodified lines | ||
| 171 | 171 | [RDMA_NLDEV_ATTR_PARENT_NAME] = { .type = NLA_NUL_STRING }, |
| 172 | 172 | [RDMA_NLDEV_ATTR_NAME_ASSIGN_TYPE] = { .type = NLA_U8 }, |
| 173 | 173 | [RDMA_NLDEV_ATTR_EVENT_TYPE] = { .type = NLA_U8 }, |
| 174 | + [RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED] = { .type = NLA_U8 }, | |
| 174 | 175 | }; |
| 175 | 176 | |
| 176 | 177 | static int put_driver_name_print_type(struct sk_buff *msg, const char *name, |
| @@ -2028,6 +2029,7 @@ static int nldev_stat_set_mode_doit(struct sk_buff *msg, · 1851 unmodified lines | ||
| 2028 | 2029 | struct ib_device *device, u32 port) |
| 2029 | 2030 | { |
| 2030 | 2031 | u32 mode, mask = 0, qpn, cntn = 0; |
| 2032 | + bool opcnt = false; | |
| 2031 | 2033 | int ret; |
| 2032 | 2034 | |
| 2033 | 2035 | /* Currently only counter for QP is supported */ |
| @@ -2035,12 +2037,17 @@ static int nldev_stat_set_mode_doit(struct sk_buff *msg, · 1 unmodified line | ||
| 2035 | 2037 | nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_RES]) != RDMA_NLDEV_ATTR_RES_QP) |
| 2036 | 2038 | return -EINVAL; |
| 2037 | 2039 | |
| 2040 | + if (tb[RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED]) | |
| 2041 | + opcnt = !!nla_get_u8( | |
| 2042 | + tb[RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED]); | |
| 2043 | + | |
| 2038 | 2044 | mode = nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_MODE]); |
| 2039 | 2045 | if (mode == RDMA_COUNTER_MODE_AUTO) { |
| 2040 | 2046 | if (tb[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK]) |
| 2041 | 2047 | mask = nla_get_u32( |
| 2042 | 2048 | 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); | |
| 2044 | 2051 | } |
| 2045 | 2052 | |
| 2046 | 2053 | if (!tb[RDMA_NLDEV_ATTR_RES_LQPN]) |
| @@ -2358,6 +2365,7 @@ static int stat_get_doit_qp(struct sk_buff *skb, struct nlmsghdr *nlh, · 311 unmodified lines | ||
| 2358 | 2365 | struct ib_device *device; |
| 2359 | 2366 | struct sk_buff *msg; |
| 2360 | 2367 | u32 index, port; |
| 2368 | + bool opcnt; | |
| 2361 | 2369 | int ret; |
| 2362 | 2370 | |
| 2363 | 2371 | 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, · 29 unmodified lines | ||
| 2393 | 2401 | goto err_msg; |
| 2394 | 2402 | } |
| 2395 | 2403 | |
| 2396 | − ret = rdma_counter_get_mode(device, port, &mode, &mask); | |
| 2404 | + ret = rdma_counter_get_mode(device, port, &mode, &mask, &opcnt); | |
| 2397 | 2405 | if (ret) |
| 2398 | 2406 | goto err_msg; |
| 2399 | 2407 | |
| @@ -2410,6 +2418,12 @@ static int stat_get_doit_qp(struct sk_buff *skb, struct nlmsghdr *nlh, · 10 unmodified lines | ||
| 2410 | 2418 | goto err_msg; |
| 2411 | 2419 | } |
| 2412 | 2420 | |
| 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 | + | |
| 2413 | 2427 | nlmsg_end(msg, nlh); |
| 2414 | 2428 | ib_device_put(device); |
| 2415 | 2429 | return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid); |
| @@ -23,6 +23,7 @@ struct rdma_counter_mode { · 22 unmodified lines | ||
| 23 | 23 | enum rdma_nl_counter_mode mode; |
| 24 | 24 | enum rdma_nl_counter_mask mask; |
| 25 | 25 | struct auto_mode_param param; |
| 26 | + bool bind_opcnt; | |
| 26 | 27 | }; |
| 27 | 28 | |
| 28 | 29 | struct rdma_port_counter { |
| @@ -47,6 +48,7 @@ void rdma_counter_init(struct ib_device *dev); · 18 unmodified lines | ||
| 47 | 48 | void rdma_counter_release(struct ib_device *dev); |
| 48 | 49 | int rdma_counter_set_auto_mode(struct ib_device *dev, u32 port, |
| 49 | 50 | enum rdma_nl_counter_mask mask, |
| 51 | + bool bind_opcnt, | |
| 50 | 52 | struct netlink_ext_ack *extack); |
| 51 | 53 | int rdma_counter_bind_qp_auto(struct ib_qp *qp, u32 port); |
| 52 | 54 | 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, · 8 unmodified lines | ||
| 61 | 63 | u32 qp_num, u32 counter_id); |
| 62 | 64 | int rdma_counter_get_mode(struct ib_device *dev, u32 port, |
| 63 | 65 | enum rdma_nl_counter_mode *mode, |
| 64 | − enum rdma_nl_counter_mask *mask); | |
| 66 | + enum rdma_nl_counter_mask *mask, | |
| 67 | + bool *opcnt); | |
| 65 | 68 | |
| 66 | 69 | int rdma_counter_modify(struct ib_device *dev, u32 port, |
| 67 | 70 | unsigned int index, bool enable); |
| @@ -580,6 +580,8 @@ enum rdma_nldev_attr { · 579 unmodified lines | ||
| 580 | 580 | RDMA_NLDEV_ATTR_EVENT_TYPE, /* u8 */ |
| 581 | 581 | |
| 582 | 582 | RDMA_NLDEV_SYS_ATTR_MONITOR_MODE, /* u8 */ |
| 583 | + | |
| 584 | + RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED, /* u8 */ | |
| 583 | 585 | /* |
| 584 | 586 | * Always the end |
| 585 | 587 | */ |