RDMA: Move uverbs_abi_ver into struct ib_device_ops
authorJason Gunthorpe <jgg@mellanox.com>
Wed, 5 Jun 2019 17:39:25 +0000 (14:39 -0300)
committerJason Gunthorpe <jgg@mellanox.com>
Mon, 10 Jun 2019 19:56:02 +0000 (16:56 -0300)
No reason for every driver to emit code to set this, just make it part of
the driver's existing static const ops structure.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
20 files changed:
drivers/infiniband/core/device.c
drivers/infiniband/core/uverbs_main.c
drivers/infiniband/hw/bnxt_re/ib_verbs.c
drivers/infiniband/hw/bnxt_re/main.c
drivers/infiniband/hw/cxgb3/iwch_provider.c
drivers/infiniband/hw/cxgb4/provider.c
drivers/infiniband/hw/efa/efa_main.c
drivers/infiniband/hw/hns/hns_roce_main.c
drivers/infiniband/hw/i40iw/i40iw_verbs.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/mthca/mthca_provider.c
drivers/infiniband/hw/nes/nes_verbs.c
drivers/infiniband/hw/ocrdma/ocrdma_main.c
drivers/infiniband/hw/qedr/main.c
drivers/infiniband/hw/usnic/usnic_ib_main.c
drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c
drivers/infiniband/sw/rdmavt/vt.c
drivers/infiniband/sw/rxe/rxe_verbs.c
include/rdma/ib_verbs.h

index 538d01f..a00b7fc 100644 (file)
@@ -2323,6 +2323,8 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
                        dev_ops->driver_id != ops->driver_id);
                dev_ops->driver_id = ops->driver_id;
        }
+       if (ops->uverbs_abi_ver)
+               dev_ops->uverbs_abi_ver = ops->uverbs_abi_ver;
 
        SET_DEVICE_OP(dev_ops, add_gid);
        SET_DEVICE_OP(dev_ops, advise_mr);
index 84a5e9a..0f8a286 100644 (file)
@@ -1186,7 +1186,7 @@ static ssize_t abi_version_show(struct device *device,
        srcu_key = srcu_read_lock(&dev->disassociate_srcu);
        ib_dev = srcu_dereference(dev->ib_dev, &dev->disassociate_srcu);
        if (ib_dev)
-               ret = sprintf(buf, "%d\n", ib_dev->uverbs_abi_ver);
+               ret = sprintf(buf, "%u\n", ib_dev->ops.uverbs_abi_ver);
        srcu_read_unlock(&dev->disassociate_srcu, srcu_key);
 
        return ret;
index 2c3685f..8af8e14 100644 (file)
@@ -3630,10 +3630,10 @@ int bnxt_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata)
        u32 chip_met_rev_num = 0;
        int rc;
 
-       dev_dbg(rdev_to_dev(rdev), "ABI version requested %d",
-               ibdev->uverbs_abi_ver);
+       dev_dbg(rdev_to_dev(rdev), "ABI version requested %u",
+               ibdev->ops.uverbs_abi_ver);
 
-       if (ibdev->uverbs_abi_ver != BNXT_RE_ABI_VERSION) {
+       if (ibdev->ops.uverbs_abi_ver != BNXT_RE_ABI_VERSION) {
                dev_dbg(rdev_to_dev(rdev), " is different from the device %d ",
                        BNXT_RE_ABI_VERSION);
                return -EPERM;
index 1ef5f83..a45cb9e 100644 (file)
@@ -597,6 +597,7 @@ static void bnxt_re_unregister_ib(struct bnxt_re_dev *rdev)
 
 static const struct ib_device_ops bnxt_re_dev_ops = {
        .driver_id = RDMA_DRIVER_BNXT_RE,
+       .uverbs_abi_ver = BNXT_RE_ABI_VERSION,
 
        .add_gid = bnxt_re_add_gid,
        .alloc_hw_stats = bnxt_re_ib_alloc_hw_stats,
@@ -663,7 +664,6 @@ static int bnxt_re_register_ib(struct bnxt_re_dev *rdev)
        ibdev->local_dma_lkey = BNXT_QPLIB_RSVD_LKEY;
 
        /* User space */
-       ibdev->uverbs_abi_ver = BNXT_RE_ABI_VERSION;
        ibdev->uverbs_cmd_mask =
                        (1ull << IB_USER_VERBS_CMD_GET_CONTEXT)         |
                        (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE)        |
index 9a9527f..5b41060 100644 (file)
@@ -1237,6 +1237,7 @@ static void get_dev_fw_ver_str(struct ib_device *ibdev, char *str)
 
 static const struct ib_device_ops iwch_dev_ops = {
        .driver_id = RDMA_DRIVER_CXGB3,
+       .uverbs_abi_ver = IWCH_UVERBS_ABI_VERSION,
 
        .alloc_hw_stats = iwch_alloc_stats,
        .alloc_mr = iwch_alloc_mr,
@@ -1316,7 +1317,6 @@ int iwch_register_device(struct iwch_dev *dev)
        dev->ibdev.phys_port_cnt = dev->rdev.port_info.nports;
        dev->ibdev.num_comp_vectors = 1;
        dev->ibdev.dev.parent = &dev->rdev.rnic_info.pdev->dev;
-       dev->ibdev.uverbs_abi_ver = IWCH_UVERBS_ABI_VERSION;
 
        memcpy(dev->ibdev.iw_ifname, dev->rdev.t3cdev_p->lldev->name,
               sizeof(dev->ibdev.iw_ifname));
index 74644af..c56cdfb 100644 (file)
@@ -490,6 +490,7 @@ static int fill_res_entry(struct sk_buff *msg, struct rdma_restrack_entry *res)
 
 static const struct ib_device_ops c4iw_dev_ops = {
        .driver_id = RDMA_DRIVER_CXGB4,
+       .uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION,
 
        .alloc_hw_stats = c4iw_alloc_stats,
        .alloc_mr = c4iw_alloc_mr,
@@ -595,7 +596,6 @@ void c4iw_register_device(struct work_struct *work)
        dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports;
        dev->ibdev.num_comp_vectors =  dev->rdev.lldi.nciq;
        dev->ibdev.dev.parent = &dev->rdev.lldi.pdev->dev;
-       dev->ibdev.uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION;
 
        memcpy(dev->ibdev.iw_ifname, dev->rdev.lldi.ports[0]->name,
               sizeof(dev->ibdev.iw_ifname));
index 3803dd4..b05c5a0 100644 (file)
@@ -198,6 +198,7 @@ static void efa_stats_init(struct efa_dev *dev)
 
 static const struct ib_device_ops efa_dev_ops = {
        .driver_id = RDMA_DRIVER_EFA,
+       .uverbs_abi_ver = EFA_UVERBS_ABI_VERSION,
 
        .alloc_pd = efa_alloc_pd,
        .alloc_ucontext = efa_alloc_ucontext,
@@ -266,7 +267,6 @@ static int efa_ib_device_add(struct efa_dev *dev)
        dev->ibdev.phys_port_cnt = 1;
        dev->ibdev.num_comp_vectors = 1;
        dev->ibdev.dev.parent = &pdev->dev;
-       dev->ibdev.uverbs_abi_ver = EFA_UVERBS_ABI_VERSION;
 
        dev->ibdev.uverbs_cmd_mask =
                (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
index dd408f8..e496b06 100644 (file)
@@ -415,6 +415,7 @@ static void hns_roce_unregister_device(struct hns_roce_dev *hr_dev)
 
 static const struct ib_device_ops hns_roce_dev_ops = {
        .driver_id = RDMA_DRIVER_HNS,
+       .uverbs_abi_ver = 1,
 
        .add_gid = hns_roce_add_gid,
        .alloc_pd = hns_roce_alloc_pd,
@@ -489,7 +490,6 @@ static int hns_roce_register_device(struct hns_roce_dev *hr_dev)
        ib_dev->phys_port_cnt           = hr_dev->caps.num_ports;
        ib_dev->local_dma_lkey          = hr_dev->caps.reserved_lkey;
        ib_dev->num_comp_vectors        = hr_dev->caps.num_comp_vectors;
-       ib_dev->uverbs_abi_ver          = 1;
        ib_dev->uverbs_cmd_mask         =
                (1ULL << IB_USER_VERBS_CMD_GET_CONTEXT) |
                (1ULL << IB_USER_VERBS_CMD_QUERY_DEVICE) |
index 1979cef..4dc647c 100644 (file)
@@ -2651,6 +2651,8 @@ static int i40iw_query_pkey(struct ib_device *ibdev,
 
 static const struct ib_device_ops i40iw_dev_ops = {
        .driver_id = RDMA_DRIVER_I40IW,
+       /* NOTE: Older kernels wrongly use 0 for the uverbs_abi_ver */
+       .uverbs_abi_ver = I40IW_ABI_VER,
 
        .alloc_hw_stats = i40iw_alloc_hw_stats,
        .alloc_mr = i40iw_alloc_mr,
index 03847e2..1f87221 100644 (file)
@@ -1089,7 +1089,8 @@ static int mlx4_ib_alloc_ucontext(struct ib_ucontext *uctx,
        if (!dev->ib_active)
                return -EAGAIN;
 
-       if (ibdev->uverbs_abi_ver == MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION) {
+       if (ibdev->ops.uverbs_abi_ver ==
+           MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION) {
                resp_v3.qp_tab_size      = dev->dev->caps.num_qps;
                resp_v3.bf_reg_size      = dev->dev->caps.bf_reg_size;
                resp_v3.bf_regs_per_page = dev->dev->caps.bf_regs_per_page;
@@ -1111,7 +1112,7 @@ static int mlx4_ib_alloc_ucontext(struct ib_ucontext *uctx,
        INIT_LIST_HEAD(&context->wqn_ranges_list);
        mutex_init(&context->wqn_ranges_mutex);
 
-       if (ibdev->uverbs_abi_ver == MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION)
+       if (ibdev->ops.uverbs_abi_ver == MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION)
                err = ib_copy_to_udata(udata, &resp_v3, sizeof(resp_v3));
        else
                err = ib_copy_to_udata(udata, &resp, sizeof(resp));
@@ -2510,6 +2511,7 @@ static void get_fw_ver_str(struct ib_device *device, char *str)
 
 static const struct ib_device_ops mlx4_ib_dev_ops = {
        .driver_id = RDMA_DRIVER_MLX4,
+       .uverbs_abi_ver = MLX4_IB_UVERBS_ABI_VERSION,
 
        .add_gid = mlx4_ib_add_gid,
        .alloc_mr = mlx4_ib_alloc_mr,
@@ -2653,11 +2655,6 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
        ibdev->ib_dev.num_comp_vectors  = dev->caps.num_comp_vectors;
        ibdev->ib_dev.dev.parent        = &dev->persist->pdev->dev;
 
-       if (dev->caps.userspace_caps)
-               ibdev->ib_dev.uverbs_abi_ver = MLX4_IB_UVERBS_ABI_VERSION;
-       else
-               ibdev->ib_dev.uverbs_abi_ver = MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION;
-
        ibdev->ib_dev.uverbs_cmd_mask   =
                (1ull << IB_USER_VERBS_CMD_GET_CONTEXT)         |
                (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE)        |
@@ -2731,6 +2728,10 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
                ib_set_device_ops(&ibdev->ib_dev, &mlx4_ib_dev_fs_ops);
        }
 
+       if (!dev->caps.userspace_caps)
+               ibdev->ib_dev.ops.uverbs_abi_ver =
+                       MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION;
+
        mlx4_ib_alloc_eqs(dev, ibdev);
 
        spin_lock_init(&iboe->lock);
index abd416a..0c23ecc 100644 (file)
@@ -6125,6 +6125,7 @@ static void mlx5_ib_stage_flow_db_cleanup(struct mlx5_ib_dev *dev)
 
 static const struct ib_device_ops mlx5_ib_dev_ops = {
        .driver_id = RDMA_DRIVER_MLX5,
+       .uverbs_abi_ver = MLX5_IB_UVERBS_ABI_VERSION,
 
        .add_gid = mlx5_ib_add_gid,
        .alloc_mr = mlx5_ib_alloc_mr,
@@ -6223,7 +6224,6 @@ static int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev)
        struct mlx5_core_dev *mdev = dev->mdev;
        int err;
 
-       dev->ib_dev.uverbs_abi_ver      = MLX5_IB_UVERBS_ABI_VERSION;
        dev->ib_dev.uverbs_cmd_mask     =
                (1ull << IB_USER_VERBS_CMD_GET_CONTEXT)         |
                (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE)        |
index d6467da..690c65a 100644 (file)
@@ -1154,6 +1154,7 @@ static void get_dev_fw_str(struct ib_device *device, char *str)
 
 static const struct ib_device_ops mthca_dev_ops = {
        .driver_id = RDMA_DRIVER_MTHCA,
+       .uverbs_abi_ver = MTHCA_UVERBS_ABI_VERSION,
 
        .alloc_pd = mthca_alloc_pd,
        .alloc_ucontext = mthca_alloc_ucontext,
@@ -1247,7 +1248,6 @@ int mthca_register_device(struct mthca_dev *dev)
 
        dev->ib_dev.owner                = THIS_MODULE;
 
-       dev->ib_dev.uverbs_abi_ver       = MTHCA_UVERBS_ABI_VERSION;
        dev->ib_dev.uverbs_cmd_mask      =
                (1ull << IB_USER_VERBS_CMD_GET_CONTEXT)         |
                (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE)        |
index 3c85e2e..f1fdd68 100644 (file)
@@ -3559,6 +3559,8 @@ static void get_dev_fw_str(struct ib_device *dev, char *str)
 
 static const struct ib_device_ops nes_dev_ops = {
        .driver_id = RDMA_DRIVER_NES,
+       /* NOTE: Older kernels wrongly use 0 for the uverbs_abi_ver */
+       .uverbs_abi_ver = NES_ABI_USERSPACE_VER,
 
        .alloc_mr = nes_alloc_mr,
        .alloc_mw = nes_alloc_mw,
index a9da4b8..ef823f1 100644 (file)
@@ -145,6 +145,7 @@ static const struct attribute_group ocrdma_attr_group = {
 
 static const struct ib_device_ops ocrdma_dev_ops = {
        .driver_id = RDMA_DRIVER_OCRDMA,
+       .uverbs_abi_ver = OCRDMA_ABI_VERSION,
 
        .alloc_mr = ocrdma_alloc_mr,
        .alloc_pd = ocrdma_alloc_pd,
@@ -203,7 +204,6 @@ static int ocrdma_register_device(struct ocrdma_dev *dev)
        memcpy(dev->ibdev.node_desc, OCRDMA_NODE_DESC,
               sizeof(OCRDMA_NODE_DESC));
        dev->ibdev.owner = THIS_MODULE;
-       dev->ibdev.uverbs_abi_ver = OCRDMA_ABI_VERSION;
        dev->ibdev.uverbs_cmd_mask =
            OCRDMA_UVERBS(GET_CONTEXT) |
            OCRDMA_UVERBS(QUERY_DEVICE) |
index 7377452..793e257 100644 (file)
@@ -184,6 +184,7 @@ static void qedr_roce_register_device(struct qedr_dev *dev)
 
 static const struct ib_device_ops qedr_dev_ops = {
        .driver_id = RDMA_DRIVER_QEDR,
+       .uverbs_abi_ver = QEDR_ABI_VERSION,
 
        .alloc_mr = qedr_alloc_mr,
        .alloc_pd = qedr_alloc_pd,
@@ -234,7 +235,6 @@ static int qedr_register_device(struct qedr_dev *dev)
        dev->ibdev.node_guid = dev->attr.node_guid;
        memcpy(dev->ibdev.node_desc, QEDR_NODE_DESC, sizeof(QEDR_NODE_DESC));
        dev->ibdev.owner = THIS_MODULE;
-       dev->ibdev.uverbs_abi_ver = QEDR_ABI_VERSION;
 
        dev->ibdev.uverbs_cmd_mask = QEDR_UVERBS(GET_CONTEXT) |
                                     QEDR_UVERBS(QUERY_DEVICE) |
index 4783033..f616908 100644 (file)
@@ -330,6 +330,7 @@ static void usnic_get_dev_fw_str(struct ib_device *device, char *str)
 
 static const struct ib_device_ops usnic_dev_ops = {
        .driver_id = RDMA_DRIVER_USNIC,
+       .uverbs_abi_ver = USNIC_UVERBS_ABI_VERSION,
 
        .alloc_pd = usnic_ib_alloc_pd,
        .alloc_ucontext = usnic_ib_alloc_ucontext,
@@ -391,7 +392,6 @@ static void *usnic_ib_device_add(struct pci_dev *dev)
        us_ibdev->ib_dev.phys_port_cnt = USNIC_IB_PORT_CNT;
        us_ibdev->ib_dev.num_comp_vectors = USNIC_IB_NUM_COMP_VECTORS;
        us_ibdev->ib_dev.dev.parent = &dev->dev;
-       us_ibdev->ib_dev.uverbs_abi_ver = USNIC_UVERBS_ABI_VERSION;
 
        us_ibdev->ib_dev.uverbs_cmd_mask =
                (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
index 54a0b63..2a7eb28 100644 (file)
@@ -145,6 +145,7 @@ static int pvrdma_port_immutable(struct ib_device *ibdev, u8 port_num,
 
 static const struct ib_device_ops pvrdma_dev_ops = {
        .driver_id = RDMA_DRIVER_VMW_PVRDMA,
+       .uverbs_abi_ver = PVRDMA_UVERBS_ABI_VERSION,
 
        .add_gid = pvrdma_add_gid,
        .alloc_mr = pvrdma_alloc_mr,
@@ -203,7 +204,6 @@ static int pvrdma_register_device(struct pvrdma_dev *dev)
        dev->ib_dev.owner = THIS_MODULE;
        dev->ib_dev.num_comp_vectors = 1;
        dev->ib_dev.dev.parent = &dev->pdev->dev;
-       dev->ib_dev.uverbs_abi_ver = PVRDMA_UVERBS_ABI_VERSION;
        dev->ib_dev.uverbs_cmd_mask =
                (1ull << IB_USER_VERBS_CMD_GET_CONTEXT)         |
                (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE)        |
index 60700e1..639ef8a 100644 (file)
@@ -382,6 +382,8 @@ enum {
 };
 
 static const struct ib_device_ops rvt_dev_ops = {
+       .uverbs_abi_ver = RVT_UVERBS_ABI_VERSION,
+
        .alloc_fmr = rvt_alloc_fmr,
        .alloc_mr = rvt_alloc_mr,
        .alloc_pd = rvt_alloc_pd,
@@ -600,7 +602,6 @@ int rvt_register_device(struct rvt_dev_info *rdi)
         * exactly which functions rdmavt supports, nor do they know the ABI
         * version, so we do all of this sort of stuff here.
         */
-       rdi->ibdev.uverbs_abi_ver = RVT_UVERBS_ABI_VERSION;
        rdi->ibdev.uverbs_cmd_mask =
                (1ull << IB_USER_VERBS_CMD_GET_CONTEXT)         |
                (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE)        |
index 3d3130d..9e87cdb 100644 (file)
@@ -1112,6 +1112,7 @@ static int rxe_enable_driver(struct ib_device *ib_dev)
 
 static const struct ib_device_ops rxe_dev_ops = {
        .driver_id = RDMA_DRIVER_RXE,
+       .uverbs_abi_ver = RXE_UVERBS_ABI_VERSION,
 
        .alloc_hw_stats = rxe_ib_alloc_hw_stats,
        .alloc_mr = rxe_alloc_mr,
@@ -1184,7 +1185,6 @@ int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name)
        dma_coerce_mask_and_coherent(&dev->dev,
                                     dma_get_required_mask(&dev->dev));
 
-       dev->uverbs_abi_ver = RXE_UVERBS_ABI_VERSION;
        dev->uverbs_cmd_mask = BIT_ULL(IB_USER_VERBS_CMD_GET_CONTEXT)
            | BIT_ULL(IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL)
            | BIT_ULL(IB_USER_VERBS_CMD_QUERY_DEVICE)
index dacf2b5..16405b9 100644 (file)
@@ -2330,6 +2330,7 @@ struct iw_cm_conn_param;
  */
 struct ib_device_ops {
        enum rdma_driver_id driver_id;
+       u32 uverbs_abi_ver;
 
        int (*post_send)(struct ib_qp *qp, const struct ib_send_wr *send_wr,
                         const struct ib_send_wr **bad_send_wr);
@@ -2650,7 +2651,6 @@ struct ib_device {
         */
        const struct attribute_group    *groups[3];
 
-       int                          uverbs_abi_ver;
        u64                          uverbs_cmd_mask;
        u64                          uverbs_ex_cmd_mask;