RDMA: Remove rdma_set_device_sysfs_group()
authorJason Gunthorpe <jgg@nvidia.com>
Fri, 11 Jun 2021 16:00:34 +0000 (19:00 +0300)
committerJason Gunthorpe <jgg@nvidia.com>
Wed, 16 Jun 2021 23:58:32 +0000 (20:58 -0300)
The driver's device group can be specified as part of the ops structure
like the device's port group. No need for the complicated API.

Link: https://lore.kernel.org/r/8964785a34fd3a29ff5b6693493f575b717e594d.1623427137.git.leonro@nvidia.com
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
14 files changed:
drivers/infiniband/core/device.c
drivers/infiniband/hw/bnxt_re/main.c
drivers/infiniband/hw/cxgb4/provider.c
drivers/infiniband/hw/hfi1/verbs.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/mthca/mthca_provider.c
drivers/infiniband/hw/ocrdma/ocrdma_main.c
drivers/infiniband/hw/qedr/main.c
drivers/infiniband/hw/qib/qib_verbs.c
drivers/infiniband/hw/usnic/usnic_ib_main.c
drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c
drivers/infiniband/sw/rxe/rxe_verbs.c
include/rdma/ib_verbs.h

index 92f224a9748172494f8355a4a6c84491ef0f9224..53a7ec66e0d17cac47faec34cd2187da87408e40 100644 (file)
@@ -586,7 +586,6 @@ struct ib_device *_ib_alloc_device(size_t size)
                return NULL;
        }
 
-       device->groups[0] = &ib_dev_attr_group;
        rdma_init_coredev(&device->coredev, device, &init_net);
 
        INIT_LIST_HEAD(&device->event_handler_list);
@@ -1396,6 +1395,8 @@ int ib_register_device(struct ib_device *device, const char *name,
                return ret;
        }
 
+       device->groups[0] = &ib_dev_attr_group;
+       device->groups[1] = device->ops.device_group;
        ret = ib_setup_device_attrs(device);
        if (ret)
                goto cache_cleanup;
@@ -2643,6 +2644,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
        SET_DEVICE_OP(dev_ops, destroy_rwq_ind_table);
        SET_DEVICE_OP(dev_ops, destroy_srq);
        SET_DEVICE_OP(dev_ops, destroy_wq);
+       SET_DEVICE_OP(dev_ops, device_group);
        SET_DEVICE_OP(dev_ops, detach_mcast);
        SET_DEVICE_OP(dev_ops, disassociate_ucontext);
        SET_DEVICE_OP(dev_ops, drain_rq);
index cb5dc25ef6a8a6ca77e4dab7a21a5d2429cc194c..d5674026512ae3fa6535e012c2d0939c1ff972e2 100644 (file)
@@ -683,6 +683,7 @@ static const struct ib_device_ops bnxt_re_dev_ops = {
        .destroy_cq = bnxt_re_destroy_cq,
        .destroy_qp = bnxt_re_destroy_qp,
        .destroy_srq = bnxt_re_destroy_srq,
+       .device_group = &bnxt_re_dev_attr_group,
        .get_dev_fw_str = bnxt_re_query_fw_str,
        .get_dma_mr = bnxt_re_get_dma_mr,
        .get_hw_stats = bnxt_re_ib_get_hw_stats,
@@ -729,7 +730,6 @@ static int bnxt_re_register_ib(struct bnxt_re_dev *rdev)
        ibdev->dev.parent = &rdev->en_dev->pdev->dev;
        ibdev->local_dma_lkey = BNXT_QPLIB_RSVD_LKEY;
 
-       rdma_set_device_sysfs_group(ibdev, &bnxt_re_dev_attr_group);
        ib_set_device_ops(ibdev, &bnxt_re_dev_ops);
        ret = ib_device_set_netdev(&rdev->ibdev, rdev->netdev, 1);
        if (ret)
index 4e453d1dde117307b370b4f20bad22a911fd80e0..881d515eb15af76379b1d1d7874d237ac2e4381b 100644 (file)
@@ -465,6 +465,7 @@ static const struct ib_device_ops c4iw_dev_ops = {
        .destroy_cq = c4iw_destroy_cq,
        .destroy_qp = c4iw_destroy_qp,
        .destroy_srq = c4iw_destroy_srq,
+       .device_group = &c4iw_attr_group,
        .fill_res_cq_entry = c4iw_fill_res_cq_entry,
        .fill_res_cm_id_entry = c4iw_fill_res_cm_id_entry,
        .fill_res_mr_entry = c4iw_fill_res_mr_entry,
@@ -539,7 +540,6 @@ void c4iw_register_device(struct work_struct *work)
        memcpy(dev->ibdev.iw_ifname, dev->rdev.lldi.ports[0]->name,
               sizeof(dev->ibdev.iw_ifname));
 
-       rdma_set_device_sysfs_group(&dev->ibdev, &c4iw_attr_group);
        ib_set_device_ops(&dev->ibdev, &c4iw_dev_ops);
        ret = set_netdevs(&dev->ibdev, &dev->rdev);
        if (ret)
index 49c6ed267a478ed045a601196b98729c44455aab..9b198c35e1a1af32b29d2dc8cc42733a5c35126d 100644 (file)
@@ -1789,6 +1789,7 @@ static const struct ib_device_ops hfi1_dev_ops = {
        .alloc_hw_device_stats = hfi1_alloc_hw_device_stats,
        .alloc_hw_port_stats = hfi_alloc_hw_port_stats,
        .alloc_rdma_netdev = hfi1_vnic_alloc_rn,
+       .device_group = &ib_hfi1_attr_group,
        .get_dev_fw_str = hfi1_get_dev_fw_str,
        .get_hw_stats = get_hw_stats,
        .modify_device = modify_device,
@@ -1927,9 +1928,6 @@ int hfi1_register_ib_device(struct hfi1_devdata *dd)
                              i,
                              ppd->pkeys);
 
-       rdma_set_device_sysfs_group(&dd->verbs_dev.rdi.ibdev,
-                                   &ib_hfi1_attr_group);
-
        ret = rvt_register_device(&dd->verbs_dev.rdi);
        if (ret)
                goto err_verbs_txreq;
index 341162aa2175c449e972e1c42e508f6ab87ea71b..6cdcbbc5384358d724b1c997445dfd96b927ca54 100644 (file)
@@ -2547,6 +2547,7 @@ static const struct ib_device_ops mlx4_ib_dev_ops = {
        .destroy_qp = mlx4_ib_destroy_qp,
        .destroy_srq = mlx4_ib_destroy_srq,
        .detach_mcast = mlx4_ib_mcg_detach,
+       .device_group = &mlx4_attr_group,
        .disassociate_ucontext = mlx4_ib_disassociate_ucontext,
        .drain_rq = mlx4_ib_drain_rq,
        .drain_sq = mlx4_ib_drain_sq,
@@ -2806,7 +2807,6 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
        if (mlx4_ib_alloc_diag_counters(ibdev))
                goto err_steer_free_bitmap;
 
-       rdma_set_device_sysfs_group(&ibdev->ib_dev, &mlx4_attr_group);
        if (ib_register_device(&ibdev->ib_dev, "mlx4_%d",
                               &dev->persist->pdev->dev))
                goto err_diag_counters;
index 18f5fc8fc23d4a08e105eebb453965dc00c0f994..b145e477e3bac88b19fe6a75cbb2b2b3291cf4fd 100644 (file)
@@ -3742,6 +3742,7 @@ static const struct ib_device_ops mlx5_ib_dev_ops = {
        .disassociate_ucontext = mlx5_ib_disassociate_ucontext,
        .drain_rq = mlx5_ib_drain_rq,
        .drain_sq = mlx5_ib_drain_sq,
+       .device_group = &mlx5_attr_group,
        .enable_driver = mlx5_ib_enable_driver,
        .get_dev_fw_str = get_dev_fw_str,
        .get_dma_mr = mlx5_ib_get_dma_mr,
@@ -4029,7 +4030,6 @@ static int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev)
 {
        const char *name;
 
-       rdma_set_device_sysfs_group(&dev->ib_dev, &mlx5_attr_group);
        if (!mlx5_lag_is_roce(dev->mdev))
                name = "mlx5_%d";
        else
index 522bb606120e224bc02321c8ee96bb8b2c676568..adf4fcf0fee47c5109b0c665734756505defba12 100644 (file)
@@ -1099,6 +1099,7 @@ static const struct ib_device_ops mthca_dev_ops = {
        .destroy_cq = mthca_destroy_cq,
        .destroy_qp = mthca_destroy_qp,
        .detach_mcast = mthca_multicast_detach,
+       .device_group = &mthca_attr_group,
        .get_dev_fw_str = get_dev_fw_str,
        .get_dma_mr = mthca_get_dma_mr,
        .get_port_immutable = mthca_port_immutable,
@@ -1186,7 +1187,6 @@ int mthca_register_device(struct mthca_dev *dev)
 
        mutex_init(&dev->cap_mask_mutex);
 
-       rdma_set_device_sysfs_group(&dev->ib_dev, &mthca_attr_group);
        ret = ib_register_device(&dev->ib_dev, "mthca%d", &dev->pdev->dev);
        if (ret)
                return ret;
index 4882b3156edb75532af634a723a56809f2c60853..f329db0c591f088bc0154e36bdc87971f69a89bc 100644 (file)
@@ -161,6 +161,7 @@ static const struct ib_device_ops ocrdma_dev_ops = {
        .destroy_ah = ocrdma_destroy_ah,
        .destroy_cq = ocrdma_destroy_cq,
        .destroy_qp = ocrdma_destroy_qp,
+       .device_group = &ocrdma_attr_group,
        .get_dev_fw_str = get_dev_fw_str,
        .get_dma_mr = ocrdma_get_dma_mr,
        .get_link_layer = ocrdma_link_layer,
@@ -218,7 +219,6 @@ static int ocrdma_register_device(struct ocrdma_dev *dev)
        if (ocrdma_get_asic_type(dev) == OCRDMA_ASIC_GEN_SKH_R)
                ib_set_device_ops(&dev->ibdev, &ocrdma_dev_srq_ops);
 
-       rdma_set_device_sysfs_group(&dev->ibdev, &ocrdma_attr_group);
        ret = ib_device_set_netdev(&dev->ibdev, dev->nic_info.netdev, 1);
        if (ret)
                return ret;
index 8334a9850220be6eef3182d4d6b563d77be222e0..de98e0604f914abfb0243df211fe1b37e6160308 100644 (file)
@@ -208,6 +208,7 @@ static const struct ib_device_ops qedr_dev_ops = {
        .destroy_cq = qedr_destroy_cq,
        .destroy_qp = qedr_destroy_qp,
        .destroy_srq = qedr_destroy_srq,
+       .device_group = &qedr_attr_group,
        .get_dev_fw_str = qedr_get_dev_fw_str,
        .get_dma_mr = qedr_get_dma_mr,
        .get_link_layer = qedr_link_layer,
@@ -256,7 +257,6 @@ static int qedr_register_device(struct qedr_dev *dev)
        dev->ibdev.num_comp_vectors = dev->num_cnq;
        dev->ibdev.dev.parent = &dev->pdev->dev;
 
-       rdma_set_device_sysfs_group(&dev->ibdev, &qedr_attr_group);
        ib_set_device_ops(&dev->ibdev, &qedr_dev_ops);
 
        rc = ib_device_set_netdev(&dev->ibdev, dev->ndev, 1);
index 8640a75d61d9ac9dd29765018f3fba437aa3c873..ef91bff5c23ca8c949304af137f385c927805cfd 100644 (file)
@@ -1484,6 +1484,7 @@ static const struct ib_device_ops qib_dev_ops = {
        .driver_id = RDMA_DRIVER_QIB,
 
        .port_groups = qib_attr_port_groups,
+       .device_group = &qib_attr_group,
        .modify_device = qib_modify_device,
        .process_mad = qib_process_mad,
 };
@@ -1612,7 +1613,6 @@ int qib_register_ib_device(struct qib_devdata *dd)
                              i,
                              dd->rcd[ctxt]->pkeys);
        }
-       rdma_set_device_sysfs_group(&dd->verbs_dev.rdi.ibdev, &qib_attr_group);
 
        ib_set_device_ops(ibdev, &qib_dev_ops);
        ret = rvt_register_device(&dd->verbs_dev.rdi);
index ff6a40e259d54db288da1057fd280bc5b54c743f..c49f9e19d92669f76df9bb126bf34e0ff4de15ec 100644 (file)
@@ -347,6 +347,7 @@ static const struct ib_device_ops usnic_dev_ops = {
        .dereg_mr = usnic_ib_dereg_mr,
        .destroy_cq = usnic_ib_destroy_cq,
        .destroy_qp = usnic_ib_destroy_qp,
+       .device_group = &usnic_attr_group,
        .get_dev_fw_str = usnic_get_dev_fw_str,
        .get_link_layer = usnic_ib_port_link_layer,
        .get_port_immutable = usnic_port_immutable,
@@ -400,8 +401,6 @@ static void *usnic_ib_device_add(struct pci_dev *dev)
 
        ib_set_device_ops(&us_ibdev->ib_dev, &usnic_dev_ops);
 
-       rdma_set_device_sysfs_group(&us_ibdev->ib_dev, &usnic_attr_group);
-
        ret = ib_device_set_netdev(&us_ibdev->ib_dev, us_ibdev->netdev, 1);
        if (ret)
                goto err_fwd_dealloc;
index 6bf2d2e47d07ea16417d24cfa148e576aef7e7b5..8ed8bc24c69fe54a9f0da458a67a26420a88fc0f 100644 (file)
@@ -162,6 +162,7 @@ static const struct ib_device_ops pvrdma_dev_ops = {
        .destroy_ah = pvrdma_destroy_ah,
        .destroy_cq = pvrdma_destroy_cq,
        .destroy_qp = pvrdma_destroy_qp,
+       .device_group = &pvrdma_attr_group,
        .get_dev_fw_str = pvrdma_get_fw_ver_str,
        .get_dma_mr = pvrdma_get_dma_mr,
        .get_link_layer = pvrdma_port_link_layer,
@@ -240,7 +241,6 @@ static int pvrdma_register_device(struct pvrdma_dev *dev)
        if (ret)
                goto err_srq_free;
        spin_lock_init(&dev->srq_tbl_lock);
-       rdma_set_device_sysfs_group(&dev->ib_dev, &pvrdma_attr_group);
 
        ret = ib_register_device(&dev->ib_dev, "vmw_pvrdma%d", &dev->pdev->dev);
        if (ret)
index cd7e66341369dbd273206eb4001738a65b652ef6..c223959ac174edc02d93e0566dec215dcfd403c0 100644 (file)
@@ -1114,6 +1114,7 @@ static const struct ib_device_ops rxe_dev_ops = {
        .destroy_qp = rxe_destroy_qp,
        .destroy_srq = rxe_destroy_srq,
        .detach_mcast = rxe_detach_mcast,
+       .device_group = &rxe_attr_group,
        .enable_driver = rxe_enable_driver,
        .get_dma_mr = rxe_get_dma_mr,
        .get_hw_stats = rxe_ib_get_hw_stats,
@@ -1180,7 +1181,6 @@ int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name)
        }
        rxe->tfm = tfm;
 
-       rdma_set_device_sysfs_group(dev, &rxe_attr_group);
        err = ib_register_device(dev, ibdev_name, NULL);
        if (err)
                pr_warn("%s failed with error %d\n", __func__, err);
index 303471585dde81ab93e62a003276903df7c64ff7..9423e70a881c214a07fde964b510fefd21f518fb 100644 (file)
@@ -2300,6 +2300,12 @@ struct ib_device_ops {
        u32 uverbs_abi_ver;
        unsigned int uverbs_no_driver_id_binding:1;
 
+       /*
+        * NOTE: New drivers should not make use of device_group; instead new
+        * device parameter should be exposed via netlink command. This
+        * mechanism exists only for existing drivers.
+        */
+       const struct attribute_group *device_group;
        const struct attribute_group **port_groups;
 
        int (*post_send)(struct ib_qp *qp, const struct ib_send_wr *send_wr,
@@ -4567,28 +4573,6 @@ int rdma_init_netdev(struct ib_device *device, u32 port_num,
                     void (*setup)(struct net_device *),
                     struct net_device *netdev);
 
-/**
- * rdma_set_device_sysfs_group - Set device attributes group to have
- *                              driver specific sysfs entries at
- *                              for infiniband class.
- *
- * @device:    device pointer for which attributes to be created
- * @group:     Pointer to group which should be added when device
- *             is registered with sysfs.
- * rdma_set_device_sysfs_group() allows existing drivers to expose one
- * group per device to have sysfs attributes.
- *
- * NOTE: New drivers should not make use of this API; instead new device
- * parameter should be exposed via netlink command. This API and mechanism
- * exist only for existing drivers.
- */
-static inline void
-rdma_set_device_sysfs_group(struct ib_device *dev,
-                           const struct attribute_group *group)
-{
-       dev->groups[1] = group;
-}
-
 /**
  * rdma_device_to_ibdev - Get ib_device pointer from device pointer
  *
@@ -4624,7 +4608,7 @@ static inline int ibdev_to_node(struct ib_device *ibdev)
  *
  * NOTE: New drivers should not make use of this API; This API is only for
  * existing drivers who have exposed sysfs entries using
- * rdma_set_device_sysfs_group().
+ * ops->device_group.
  */
 #define rdma_device_to_drv_device(dev, drv_dev_struct, ibdev_member)           \
        container_of(rdma_device_to_ibdev(dev), drv_dev_struct, ibdev_member)