]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA/core: Introduce "name_assign_type" for an IB device
authorMark Zhang <markzhang@nvidia.com>
Mon, 1 Jul 2024 12:40:48 +0000 (15:40 +0300)
committerLeon Romanovsky <leon@kernel.org>
Thu, 4 Jul 2024 04:59:53 +0000 (07:59 +0300)
The name_assign_type indicates how the name is provided. Currently
these types are supported:
- RDMA_NAME_ASSIGN_TYPE_UNKNOWN: Unknown or not set;
- RDMA_NAME_ASSIGN_TYPE_USER: Name is provided by the user; The
  user-created sub device, rxe and siw device has this type.

When filling nl device info, it is set in the new attribute
RDMA_NLDEV_ATTR_NAME_ASSIGN_TYPE. User-space tools like udev
"rdma_rename" could check this attribute to determine if this
device needs to be renamed or not.

Signed-off-by: Mark Zhang <markzhang@nvidia.com>
Link: https://lore.kernel.org/r/522591bef9a369cc8e5dcb77787e017bffee37fe.1719837610.git.leon@kernel.org
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/core/nldev.c
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/sw/rxe/rxe_net.c
drivers/infiniband/sw/siw/siw_main.c
include/rdma/ib_verbs.h
include/uapi/rdma/rdma_netlink.h

index 025efce540a7f63ac3b5d9f3634070937b2bbc79..a6b80cdc96f73980404a44cbde3d0169ef1320f4 100644 (file)
@@ -169,6 +169,7 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
        [RDMA_NLDEV_ATTR_DRIVER_DETAILS]        = { .type = NLA_U8 },
        [RDMA_NLDEV_ATTR_DEV_TYPE]              = { .type = NLA_U8 },
        [RDMA_NLDEV_ATTR_PARENT_NAME]           = { .type = NLA_NUL_STRING },
+       [RDMA_NLDEV_ATTR_NAME_ASSIGN_TYPE]      = { .type = NLA_U8 },
 };
 
 static int put_driver_name_print_type(struct sk_buff *msg, const char *name,
@@ -312,6 +313,10 @@ static int fill_dev_info(struct sk_buff *msg, struct ib_device *device)
                           dev_name(&device->parent->dev)))
                return -EMSGSIZE;
 
+       if (nla_put_u8(msg, RDMA_NLDEV_ATTR_NAME_ASSIGN_TYPE,
+                      device->name_assign_type))
+               return -EMSGSIZE;
+
        /*
         * Link type is determined on first port and mlx4 device
         * which can potentially have two different link type for the same
index 5de0d95d1f45bde4949e10af9e19b3ad7de16ecb..33513553379cd965a9c13c8e54da16ca2454cca7 100644 (file)
@@ -4198,9 +4198,10 @@ static int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev)
 {
        const char *name;
 
-       if (dev->sub_dev_name)
+       if (dev->sub_dev_name) {
                name = dev->sub_dev_name;
-       else if (!mlx5_lag_is_active(dev->mdev))
+               ib_mark_name_assigned_by_user(&dev->ib_dev);
+       } else if (!mlx5_lag_is_active(dev->mdev))
                name = "mlx5_%d";
        else
                name = "mlx5_bond_%d";
index ca9a82e1c4c7ea96946861cef6606e3190cde16f..75d1407db52d4dbf3673c35c41dd159ee6de8d56 100644 (file)
@@ -537,6 +537,7 @@ int rxe_net_add(const char *ibdev_name, struct net_device *ndev)
                return -ENOMEM;
 
        rxe->ndev = ndev;
+       ib_mark_name_assigned_by_user(&rxe->ib_dev);
 
        err = rxe_add(rxe, ndev->mtu, ibdev_name);
        if (err) {
index 61ad8ca3d1a2a82ab5f3e696ed0388a642fe8376..b2b54242aa6916cdafaa4eb1fb2b7ac74d1b8666 100644 (file)
@@ -485,6 +485,7 @@ static int siw_newlink(const char *basedev_name, struct net_device *netdev)
                else
                        sdev->state = IB_PORT_DOWN;
 
+               ib_mark_name_assigned_by_user(&sdev->base_dev);
                rv = siw_device_register(sdev, basedev_name);
                if (rv)
                        ib_dealloc_device(&sdev->base_dev);
index e09d4f09b602cebc6fb293c89c0fd6f3c5814b9d..6c5712ae559d8fb7d964553dbfad6c5b2b565d96 100644 (file)
@@ -2794,6 +2794,8 @@ struct ib_device {
        enum rdma_nl_dev_type type;
        struct ib_device *parent;
        struct list_head subdev_list;
+
+       enum rdma_nl_name_assign_type name_assign_type;
 };
 
 static inline void *rdma_zalloc_obj(struct ib_device *dev, size_t size,
@@ -4867,4 +4869,10 @@ int ib_add_sub_device(struct ib_device *parent,
  * Return 0 on success, an error code otherwise
  */
 int ib_del_sub_device_and_put(struct ib_device *sub);
+
+static inline void ib_mark_name_assigned_by_user(struct ib_device *ibdev)
+{
+       ibdev->name_assign_type = RDMA_NAME_ASSIGN_TYPE_USER;
+}
+
 #endif /* IB_VERBS_H */
index 4b69242d784897ec4110b62b73afd9f954def167..2f37568f555618d35d8a1e7a1c27512a2faa604a 100644 (file)
@@ -572,6 +572,8 @@ enum rdma_nldev_attr {
 
        RDMA_NLDEV_ATTR_PARENT_NAME,            /* string */
 
+       RDMA_NLDEV_ATTR_NAME_ASSIGN_TYPE,       /* u8 */
+
        /*
         * Always the end
         */
@@ -615,4 +617,11 @@ enum rdma_nl_counter_mask {
 enum rdma_nl_dev_type {
        RDMA_DEVICE_TYPE_SMI = 1,
 };
+
+/* RDMA device name assignment types */
+enum rdma_nl_name_assign_type {
+       RDMA_NAME_ASSIGN_TYPE_UNKNOWN = 0,
+       RDMA_NAME_ASSIGN_TYPE_USER = 1, /* Provided by user-space */
+};
+
 #endif /* _UAPI_RDMA_NETLINK_H */