]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
IB/core: Add query_port_speed verb
authorOr Har-Toov <ohartoov@nvidia.com>
Thu, 18 Dec 2025 15:58:46 +0000 (17:58 +0200)
committerLeon Romanovsky <leon@kernel.org>
Mon, 5 Jan 2026 07:43:05 +0000 (02:43 -0500)
Add new ibv_query_port_speed() verb to enable applications to query
the effective bandwidth of a port.

This verb is particularly useful when the speed is not a multiplication
of IB speed and width where width is 2^n.

Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Edward Srouji <edwards@nvidia.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/core/device.c
drivers/infiniband/core/uverbs_std_types_device.c
include/rdma/ib_verbs.h
include/uapi/rdma/ib_user_ioctl_cmds.h

index 13e8a1714bbd7ff49af3c1a9bd83640c5e904dc2..04edc57592aae37eaea12102dd850e0effdf0cc0 100644 (file)
@@ -2816,6 +2816,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
        SET_DEVICE_OP(dev_ops, query_gid);
        SET_DEVICE_OP(dev_ops, query_pkey);
        SET_DEVICE_OP(dev_ops, query_port);
+       SET_DEVICE_OP(dev_ops, query_port_speed);
        SET_DEVICE_OP(dev_ops, query_qp);
        SET_DEVICE_OP(dev_ops, query_srq);
        SET_DEVICE_OP(dev_ops, query_ucontext);
index c0fd283d9d6c9f1e58f5a3e3262cdb1b0cb2644b..a28f9f21bed89de53f6ea313df8bfffc804f4dfb 100644 (file)
@@ -209,6 +209,39 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_PORT)(
                                             &resp, sizeof(resp));
 }
 
+static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_PORT_SPEED)(
+       struct uverbs_attr_bundle *attrs)
+{
+       struct ib_ucontext *ucontext;
+       struct ib_device *ib_dev;
+       u32 port_num;
+       u64 speed;
+       int ret;
+
+       ucontext = ib_uverbs_get_ucontext(attrs);
+       if (IS_ERR(ucontext))
+               return PTR_ERR(ucontext);
+       ib_dev = ucontext->device;
+
+       if (!ib_dev->ops.query_port_speed)
+               return -EOPNOTSUPP;
+
+       ret = uverbs_get_const(&port_num, attrs,
+                              UVERBS_ATTR_QUERY_PORT_SPEED_PORT_NUM);
+       if (ret)
+               return ret;
+
+       if (!rdma_is_port_valid(ib_dev, port_num))
+               return -EINVAL;
+
+       ret = ib_dev->ops.query_port_speed(ib_dev, port_num, &speed);
+       if (ret)
+               return ret;
+
+       return uverbs_copy_to(attrs, UVERBS_ATTR_QUERY_PORT_SPEED_RESP,
+                             &speed, sizeof(speed));
+}
+
 static int UVERBS_HANDLER(UVERBS_METHOD_GET_CONTEXT)(
        struct uverbs_attr_bundle *attrs)
 {
@@ -469,6 +502,14 @@ DECLARE_UVERBS_NAMED_METHOD(
                                   active_speed_ex),
                UA_MANDATORY));
 
+DECLARE_UVERBS_NAMED_METHOD(
+       UVERBS_METHOD_QUERY_PORT_SPEED,
+       UVERBS_ATTR_CONST_IN(UVERBS_ATTR_QUERY_PORT_SPEED_PORT_NUM, u32,
+                            UA_MANDATORY),
+       UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_QUERY_PORT_SPEED_RESP,
+                           UVERBS_ATTR_TYPE(u64),
+                           UA_MANDATORY));
+
 DECLARE_UVERBS_NAMED_METHOD(
        UVERBS_METHOD_QUERY_GID_TABLE,
        UVERBS_ATTR_CONST_IN(UVERBS_ATTR_QUERY_GID_TABLE_ENTRY_SIZE, u64,
@@ -498,6 +539,7 @@ DECLARE_UVERBS_GLOBAL_METHODS(UVERBS_OBJECT_DEVICE,
                              &UVERBS_METHOD(UVERBS_METHOD_INVOKE_WRITE),
                              &UVERBS_METHOD(UVERBS_METHOD_INFO_HANDLES),
                              &UVERBS_METHOD(UVERBS_METHOD_QUERY_PORT),
+                             &UVERBS_METHOD(UVERBS_METHOD_QUERY_PORT_SPEED),
                              &UVERBS_METHOD(UVERBS_METHOD_QUERY_CONTEXT),
                              &UVERBS_METHOD(UVERBS_METHOD_QUERY_GID_TABLE),
                              &UVERBS_METHOD(UVERBS_METHOD_QUERY_GID_ENTRY));
index b984f9581a731347692166820808a3317167da5f..a4786395328a423e61f9c6255b6437043e34f9c1 100644 (file)
@@ -2418,6 +2418,8 @@ struct ib_device_ops {
                                                     int comp_vector);
        int (*query_port)(struct ib_device *device, u32 port_num,
                          struct ib_port_attr *port_attr);
+       int (*query_port_speed)(struct ib_device *device, u32 port_num,
+                               u64 *speed);
        int (*modify_port)(struct ib_device *device, u32 port_num,
                           int port_modify_mask,
                           struct ib_port_modify *port_modify);
index de6f5a94f1e33964a0c7906c0d6895b56aa90ab4..35da4026f452b48f994c9c652f051ff6067a10ad 100644 (file)
@@ -73,6 +73,7 @@ enum uverbs_methods_device {
        UVERBS_METHOD_QUERY_CONTEXT,
        UVERBS_METHOD_QUERY_GID_TABLE,
        UVERBS_METHOD_QUERY_GID_ENTRY,
+       UVERBS_METHOD_QUERY_PORT_SPEED,
 };
 
 enum uverbs_attrs_invoke_write_cmd_attr_ids {
@@ -86,6 +87,11 @@ enum uverbs_attrs_query_port_cmd_attr_ids {
        UVERBS_ATTR_QUERY_PORT_RESP,
 };
 
+enum uverbs_attrs_query_port_speed_cmd_attr_ids {
+       UVERBS_ATTR_QUERY_PORT_SPEED_PORT_NUM,
+       UVERBS_ATTR_QUERY_PORT_SPEED_RESP,
+};
+
 enum uverbs_attrs_get_context_attr_ids {
        UVERBS_ATTR_GET_CONTEXT_NUM_COMP_VECTORS,
        UVERBS_ATTR_GET_CONTEXT_CORE_SUPPORT,