Skip to content

Commit

Permalink
RDMA: Move driver_id into struct ib_device_ops
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jason Gunthorpe committed Jun 10, 2019
1 parent a1a8e4a commit b9560a4
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 25 deletions.
12 changes: 9 additions & 3 deletions drivers/infiniband/core/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ struct ib_device *ib_device_get_by_name(const char *name,
down_read(&devices_rwsem);
device = __ib_device_get_by_name(name);
if (device && driver_id != RDMA_DRIVER_UNKNOWN &&
device->driver_id != driver_id)
device->ops.driver_id != driver_id)
device = NULL;

if (device) {
Expand Down Expand Up @@ -1456,7 +1456,7 @@ void ib_unregister_driver(enum rdma_driver_id driver_id)

down_read(&devices_rwsem);
xa_for_each (&devices, index, ib_dev) {
if (ib_dev->driver_id != driver_id)
if (ib_dev->ops.driver_id != driver_id)
continue;

get_device(&ib_dev->dev);
Expand Down Expand Up @@ -2013,7 +2013,7 @@ struct ib_device *ib_device_get_by_netdev(struct net_device *ndev,
(uintptr_t)ndev) {
if (rcu_access_pointer(cur->netdev) == ndev &&
(driver_id == RDMA_DRIVER_UNKNOWN ||
cur->ib_dev->driver_id == driver_id) &&
cur->ib_dev->ops.driver_id == driver_id) &&
ib_device_try_get(cur->ib_dev)) {
res = cur->ib_dev;
break;
Expand Down Expand Up @@ -2318,6 +2318,12 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)

#define SET_OBJ_SIZE(ptr, name) SET_DEVICE_OP(ptr, size_##name)

if (ops->driver_id != RDMA_DRIVER_UNKNOWN) {
WARN_ON(dev_ops->driver_id != RDMA_DRIVER_UNKNOWN &&
dev_ops->driver_id != ops->driver_id);
dev_ops->driver_id = ops->driver_id;
}

SET_DEVICE_OP(dev_ops, add_gid);
SET_DEVICE_OP(dev_ops, advise_mr);
SET_DEVICE_OP(dev_ops, alloc_dm);
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/core/uverbs_uapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ struct uverbs_api *uverbs_alloc_api(struct ib_device *ibdev)
return ERR_PTR(-ENOMEM);

INIT_RADIX_TREE(&uapi->radix, GFP_KERNEL);
uapi->driver_id = ibdev->driver_id;
uapi->driver_id = ibdev->ops.driver_id;

rc = uapi_merge_def(uapi, ibdev, uverbs_core_api, false);
if (rc)
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/bnxt_re/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ 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,

.add_gid = bnxt_re_add_gid,
.alloc_hw_stats = bnxt_re_ib_alloc_hw_stats,
.alloc_mr = bnxt_re_alloc_mr,
Expand Down Expand Up @@ -691,7 +693,6 @@ static int bnxt_re_register_ib(struct bnxt_re_dev *rdev)


rdma_set_device_sysfs_group(ibdev, &bnxt_re_dev_attr_group);
ibdev->driver_id = RDMA_DRIVER_BNXT_RE;
ib_set_device_ops(ibdev, &bnxt_re_dev_ops);
ret = ib_device_set_netdev(&rdev->ibdev, rdev->netdev, 1);
if (ret)
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/cxgb3/iwch_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,8 @@ 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,

.alloc_hw_stats = iwch_alloc_stats,
.alloc_mr = iwch_alloc_mr,
.alloc_mw = iwch_alloc_mw,
Expand Down Expand Up @@ -1319,7 +1321,6 @@ int iwch_register_device(struct iwch_dev *dev)
memcpy(dev->ibdev.iw_ifname, dev->rdev.t3cdev_p->lldev->name,
sizeof(dev->ibdev.iw_ifname));

dev->ibdev.driver_id = RDMA_DRIVER_CXGB3;
rdma_set_device_sysfs_group(&dev->ibdev, &iwch_attr_group);
ib_set_device_ops(&dev->ibdev, &iwch_dev_ops);
return ib_register_device(&dev->ibdev, "cxgb3_%d");
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/cxgb4/provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ 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,

.alloc_hw_stats = c4iw_alloc_stats,
.alloc_mr = c4iw_alloc_mr,
.alloc_mw = c4iw_alloc_mw,
Expand Down Expand Up @@ -599,7 +601,6 @@ void c4iw_register_device(struct work_struct *work)
sizeof(dev->ibdev.iw_ifname));

rdma_set_device_sysfs_group(&dev->ibdev, &c4iw_attr_group);
dev->ibdev.driver_id = RDMA_DRIVER_CXGB4;
ib_set_device_ops(&dev->ibdev, &c4iw_dev_ops);
ret = set_netdevs(&dev->ibdev, &dev->rdev);
if (ret)
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/efa/efa_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ static void efa_stats_init(struct efa_dev *dev)
}

static const struct ib_device_ops efa_dev_ops = {
.driver_id = RDMA_DRIVER_EFA,

.alloc_pd = efa_alloc_pd,
.alloc_ucontext = efa_alloc_ucontext,
.create_ah = efa_create_ah,
Expand Down Expand Up @@ -287,7 +289,6 @@ static int efa_ib_device_add(struct efa_dev *dev)
dev->ibdev.uverbs_ex_cmd_mask =
(1ull << IB_USER_VERBS_EX_CMD_QUERY_DEVICE);

dev->ibdev.driver_id = RDMA_DRIVER_EFA;
ib_set_device_ops(&dev->ibdev, &efa_dev_ops);

err = ib_register_device(&dev->ibdev, "efa_%d");
Expand Down
4 changes: 3 additions & 1 deletion drivers/infiniband/hw/hfi1/verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,8 @@ static int get_hw_stats(struct ib_device *ibdev, struct rdma_hw_stats *stats,
}

static const struct ib_device_ops hfi1_dev_ops = {
.driver_id = RDMA_DRIVER_HFI1,

.alloc_hw_stats = alloc_hw_stats,
.alloc_rdma_netdev = hfi1_vnic_alloc_rn,
.get_dev_fw_str = hfi1_get_dev_fw_str,
Expand Down Expand Up @@ -1923,7 +1925,7 @@ int hfi1_register_ib_device(struct hfi1_devdata *dd)
rdma_set_device_sysfs_group(&dd->verbs_dev.rdi.ibdev,
&ib_hfi1_attr_group);

ret = rvt_register_device(&dd->verbs_dev.rdi, RDMA_DRIVER_HFI1);
ret = rvt_register_device(&dd->verbs_dev.rdi);
if (ret)
goto err_verbs_txreq;

Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/hns/hns_roce_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ 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,

.add_gid = hns_roce_add_gid,
.alloc_pd = hns_roce_alloc_pd,
.alloc_ucontext = hns_roce_alloc_ucontext,
Expand Down Expand Up @@ -536,7 +538,6 @@ static int hns_roce_register_device(struct hns_roce_dev *hr_dev)
ib_set_device_ops(ib_dev, hr_dev->hw->hns_roce_dev_srq_ops);
}

ib_dev->driver_id = RDMA_DRIVER_HNS;
ib_set_device_ops(ib_dev, hr_dev->hw->hns_roce_dev_ops);
ib_set_device_ops(ib_dev, &hns_roce_dev_ops);
for (i = 0; i < hr_dev->caps.num_ports; i++) {
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/i40iw/i40iw_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2650,6 +2650,8 @@ static int i40iw_query_pkey(struct ib_device *ibdev,
}

static const struct ib_device_ops i40iw_dev_ops = {
.driver_id = RDMA_DRIVER_I40IW,

.alloc_hw_stats = i40iw_alloc_hw_stats,
.alloc_mr = i40iw_alloc_mr,
.alloc_pd = i40iw_alloc_pd,
Expand Down Expand Up @@ -2787,7 +2789,6 @@ int i40iw_register_rdma_device(struct i40iw_device *iwdev)
return -ENOMEM;
iwibdev = iwdev->iwibdev;
rdma_set_device_sysfs_group(&iwibdev->ibdev, &i40iw_attr_group);
iwibdev->ibdev.driver_id = RDMA_DRIVER_I40IW;
ret = ib_register_device(&iwibdev->ibdev, "i40iw%d");
if (ret)
goto error;
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/mlx4/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2509,6 +2509,8 @@ 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,

.add_gid = mlx4_ib_add_gid,
.alloc_mr = mlx4_ib_alloc_mr,
.alloc_pd = mlx4_ib_alloc_pd,
Expand Down Expand Up @@ -2839,7 +2841,6 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
goto err_steer_free_bitmap;

rdma_set_device_sysfs_group(&ibdev->ib_dev, &mlx4_attr_group);
ibdev->ib_dev.driver_id = RDMA_DRIVER_MLX4;
if (ib_register_device(&ibdev->ib_dev, "mlx4_%d"))
goto err_diag_counters;

Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/mlx5/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6124,6 +6124,8 @@ 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,

.add_gid = mlx5_ib_add_gid,
.alloc_mr = mlx5_ib_alloc_mr,
.alloc_pd = mlx5_ib_alloc_pd,
Expand Down Expand Up @@ -6290,7 +6292,6 @@ static int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev)
if (mlx5_accel_ipsec_device_caps(dev->mdev) &
MLX5_ACCEL_IPSEC_CAP_DEVICE)
ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_flow_ipsec_ops);
dev->ib_dev.driver_id = RDMA_DRIVER_MLX5;
ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_ops);

if (IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS))
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/mthca/mthca_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,8 @@ 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,

.alloc_pd = mthca_alloc_pd,
.alloc_ucontext = mthca_alloc_ucontext,
.attach_mcast = mthca_multicast_attach,
Expand Down Expand Up @@ -1303,7 +1305,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);
dev->ib_dev.driver_id = RDMA_DRIVER_MTHCA;
ret = ib_register_device(&dev->ib_dev, "mthca%d");
if (ret)
return ret;
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/nes/nes_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3558,6 +3558,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,

.alloc_mr = nes_alloc_mr,
.alloc_mw = nes_alloc_mw,
.alloc_pd = nes_alloc_pd,
Expand Down Expand Up @@ -3722,7 +3724,6 @@ int nes_register_ofa_device(struct nes_ib_device *nesibdev)
int ret;

rdma_set_device_sysfs_group(&nesvnic->nesibdev->ibdev, &nes_attr_group);
nesvnic->nesibdev->ibdev.driver_id = RDMA_DRIVER_NES;
ret = ib_register_device(&nesvnic->nesibdev->ibdev, "nes%d");
if (ret) {
return ret;
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/ocrdma/ocrdma_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ static const struct attribute_group ocrdma_attr_group = {
};

static const struct ib_device_ops ocrdma_dev_ops = {
.driver_id = RDMA_DRIVER_OCRDMA,

.alloc_mr = ocrdma_alloc_mr,
.alloc_pd = ocrdma_alloc_pd,
.alloc_ucontext = ocrdma_alloc_ucontext,
Expand Down Expand Up @@ -249,7 +251,6 @@ static int ocrdma_register_device(struct ocrdma_dev *dev)
ib_set_device_ops(&dev->ibdev, &ocrdma_dev_srq_ops);
}
rdma_set_device_sysfs_group(&dev->ibdev, &ocrdma_attr_group);
dev->ibdev.driver_id = RDMA_DRIVER_OCRDMA;
ret = ib_device_set_netdev(&dev->ibdev, dev->nic_info.netdev, 1);
if (ret)
return ret;
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/qedr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ static void qedr_roce_register_device(struct qedr_dev *dev)
}

static const struct ib_device_ops qedr_dev_ops = {
.driver_id = RDMA_DRIVER_QEDR,

.alloc_mr = qedr_alloc_mr,
.alloc_pd = qedr_alloc_pd,
.alloc_ucontext = qedr_alloc_ucontext,
Expand Down Expand Up @@ -274,7 +276,6 @@ static int qedr_register_device(struct qedr_dev *dev)
rdma_set_device_sysfs_group(&dev->ibdev, &qedr_attr_group);
ib_set_device_ops(&dev->ibdev, &qedr_dev_ops);

dev->ibdev.driver_id = RDMA_DRIVER_QEDR;
rc = ib_device_set_netdev(&dev->ibdev, dev->ndev, 1);
if (rc)
return rc;
Expand Down
4 changes: 3 additions & 1 deletion drivers/infiniband/hw/qib/qib_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,8 @@ static void qib_fill_device_attr(struct qib_devdata *dd)
}

static const struct ib_device_ops qib_dev_ops = {
.driver_id = RDMA_DRIVER_QIB,

.init_port = qib_create_port_files,
.modify_device = qib_modify_device,
.process_mad = qib_process_mad,
Expand Down Expand Up @@ -1616,7 +1618,7 @@ int qib_register_ib_device(struct qib_devdata *dd)
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, RDMA_DRIVER_QIB);
ret = rvt_register_device(&dd->verbs_dev.rdi);
if (ret)
goto err_tx;

Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/usnic/usnic_ib_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ 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,

.alloc_pd = usnic_ib_alloc_pd,
.alloc_ucontext = usnic_ib_alloc_ucontext,
.create_cq = usnic_ib_create_cq,
Expand Down Expand Up @@ -412,7 +414,6 @@ static void *usnic_ib_device_add(struct pci_dev *dev)

ib_set_device_ops(&us_ibdev->ib_dev, &usnic_dev_ops);

us_ibdev->ib_dev.driver_id = RDMA_DRIVER_USNIC;
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);
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ 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,

.add_gid = pvrdma_add_gid,
.alloc_mr = pvrdma_alloc_mr,
.alloc_pd = pvrdma_alloc_pd,
Expand Down Expand Up @@ -261,7 +263,6 @@ static int pvrdma_register_device(struct pvrdma_dev *dev)
if (!dev->srq_tbl)
goto err_qp_free;
}
dev->ib_dev.driver_id = RDMA_DRIVER_VMW_PVRDMA;
ret = ib_device_set_netdev(&dev->ib_dev, dev->netdev, 1);
if (ret)
return ret;
Expand Down
3 changes: 1 addition & 2 deletions drivers/infiniband/sw/rdmavt/vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ static noinline int check_support(struct rvt_dev_info *rdi, int verb)
*
* Return: 0 on success otherwise an errno.
*/
int rvt_register_device(struct rvt_dev_info *rdi, u32 driver_id)
int rvt_register_device(struct rvt_dev_info *rdi)
{
int ret = 0, i;

Expand Down Expand Up @@ -636,7 +636,6 @@ int rvt_register_device(struct rvt_dev_info *rdi, u32 driver_id)
if (!rdi->ibdev.num_comp_vectors)
rdi->ibdev.num_comp_vectors = 1;

rdi->ibdev.driver_id = driver_id;
/* We are now good to announce we exist */
ret = ib_register_device(&rdi->ibdev, dev_name(&rdi->ibdev.dev));
if (ret) {
Expand Down
3 changes: 2 additions & 1 deletion drivers/infiniband/sw/rxe/rxe_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,8 @@ static int rxe_enable_driver(struct ib_device *ib_dev)
}

static const struct ib_device_ops rxe_dev_ops = {
.driver_id = RDMA_DRIVER_RXE,

.alloc_hw_stats = rxe_ib_alloc_hw_stats,
.alloc_mr = rxe_alloc_mr,
.alloc_pd = rxe_alloc_pd,
Expand Down Expand Up @@ -1230,7 +1232,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);
dev->driver_id = RDMA_DRIVER_RXE;
err = ib_register_device(dev, ibdev_name);
if (err)
pr_warn("%s failed with error %d\n", __func__, err);
Expand Down
3 changes: 2 additions & 1 deletion include/rdma/ib_verbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2329,6 +2329,8 @@ struct iw_cm_conn_param;
* need to define the supported operations, otherwise they will be set to null.
*/
struct ib_device_ops {
enum rdma_driver_id driver_id;

int (*post_send)(struct ib_qp *qp, const struct ib_send_wr *send_wr,
const struct ib_send_wr **bad_send_wr);
int (*post_recv)(struct ib_qp *qp, const struct ib_recv_wr *recv_wr,
Expand Down Expand Up @@ -2672,7 +2674,6 @@ struct ib_device {
struct rdma_restrack_root *res;

const struct uapi_definition *driver_def;
enum rdma_driver_id driver_id;

/*
* Positive refcount indicates that the device is currently
Expand Down
2 changes: 1 addition & 1 deletion include/rdma/rdma_vt.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ static inline u16 rvt_get_pkey(struct rvt_dev_info *rdi,

struct rvt_dev_info *rvt_alloc_device(size_t size, int nports);
void rvt_dealloc_device(struct rvt_dev_info *rdi);
int rvt_register_device(struct rvt_dev_info *rvd, u32 driver_id);
int rvt_register_device(struct rvt_dev_info *rvd);
void rvt_unregister_device(struct rvt_dev_info *rvd);
int rvt_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr);
int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port,
Expand Down

0 comments on commit b9560a4

Please sign in to comment.