From: Parav Pandit <parav@xxxxxxxxxxxx> Introduce and use rdma_device_to_ibdev() API for those drivers which are registering one sysfs group. In subsequent patch, device->provider_ibdev one-to-one mapping is no longer holds true during accessing sysfs entries. Therefore, introduce an API rdma_device_to_ibdev() that provides such information. Signed-off-by: Parav Pandit <parav@xxxxxxxxxxxx> Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx> --- drivers/infiniband/hw/bnxt_re/main.c | 6 ++-- drivers/infiniband/hw/cxgb3/iwch_provider.c | 14 +++++---- drivers/infiniband/hw/cxgb4/provider.c | 14 +++++---- drivers/infiniband/hw/hfi1/sysfs.c | 24 ++++++++++------ drivers/infiniband/hw/i40iw/i40iw_verbs.c | 5 ++-- drivers/infiniband/hw/mlx4/main.c | 10 +++++-- drivers/infiniband/hw/mlx5/main.c | 18 ++++++++---- drivers/infiniband/hw/mthca/mthca_provider.c | 12 ++++++-- drivers/infiniband/hw/nes/nes_verbs.c | 3 +- drivers/infiniband/hw/ocrdma/ocrdma_main.c | 6 ++-- drivers/infiniband/hw/qedr/main.c | 3 +- drivers/infiniband/hw/qib/qib_sysfs.c | 27 ++++++++++++------ drivers/infiniband/hw/usnic/usnic_ib_sysfs.c | 30 +++++++++++--------- drivers/infiniband/sw/rxe/rxe_verbs.c | 4 +-- include/rdma/ib_verbs.h | 16 +++++++++++ 15 files changed, 129 insertions(+), 63 deletions(-) diff --git a/drivers/infiniband/hw/bnxt_re/main.c b/drivers/infiniband/hw/bnxt_re/main.c index cf2282654210..e5d110619aff 100644 --- a/drivers/infiniband/hw/bnxt_re/main.c +++ b/drivers/infiniband/hw/bnxt_re/main.c @@ -538,7 +538,8 @@ static struct bnxt_en_dev *bnxt_re_dev_probe(struct net_device *netdev) static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr, char *buf) { - struct bnxt_re_dev *rdev = to_bnxt_re_dev(device, ibdev.dev); + struct ib_device *ibdev = rdma_device_to_ibdev(device); + struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev); return scnprintf(buf, PAGE_SIZE, "0x%x\n", rdev->en_dev->pdev->vendor); } @@ -547,7 +548,8 @@ static DEVICE_ATTR_RO(hw_rev); static ssize_t hca_type_show(struct device *device, struct device_attribute *attr, char *buf) { - struct bnxt_re_dev *rdev = to_bnxt_re_dev(device, ibdev.dev); + struct ib_device *ibdev = rdma_device_to_ibdev(device); + struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev); return scnprintf(buf, PAGE_SIZE, "%s\n", rdev->ibdev.node_desc); } diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.c b/drivers/infiniband/hw/cxgb3/iwch_provider.c index ebbec02cebe0..df22f0634f59 100644 --- a/drivers/infiniband/hw/cxgb3/iwch_provider.c +++ b/drivers/infiniband/hw/cxgb3/iwch_provider.c @@ -1130,8 +1130,9 @@ static int iwch_query_port(struct ib_device *ibdev, static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct iwch_dev *iwch_dev = container_of(dev, struct iwch_dev, - ibdev.dev); + struct ib_device *ibdev = rdma_device_to_ibdev(dev); + struct iwch_dev *iwch_dev = container_of(ibdev, struct iwch_dev, ibdev); + pr_debug("%s dev 0x%p\n", __func__, dev); return sprintf(buf, "%d\n", iwch_dev->rdev.t3cdev_p->type); } @@ -1140,8 +1141,8 @@ static DEVICE_ATTR_RO(hw_rev); static ssize_t hca_type_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct iwch_dev *iwch_dev = container_of(dev, struct iwch_dev, - ibdev.dev); + struct ib_device *ibdev = rdma_device_to_ibdev(dev); + struct iwch_dev *iwch_dev = container_of(ibdev, struct iwch_dev, ibdev); struct ethtool_drvinfo info; struct net_device *lldev = iwch_dev->rdev.t3cdev_p->lldev; @@ -1154,8 +1155,9 @@ static DEVICE_ATTR_RO(hca_type); static ssize_t board_id_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct iwch_dev *iwch_dev = container_of(dev, struct iwch_dev, - ibdev.dev); + struct ib_device *ibdev = rdma_device_to_ibdev(dev); + struct iwch_dev *iwch_dev = container_of(ibdev, struct iwch_dev, ibdev); + pr_debug("%s dev 0x%p\n", __func__, dev); return sprintf(buf, "%x.%x\n", iwch_dev->rdev.rnic_info.pdev->vendor, iwch_dev->rdev.rnic_info.pdev->device); diff --git a/drivers/infiniband/hw/cxgb4/provider.c b/drivers/infiniband/hw/cxgb4/provider.c index cbb3c0ddd990..6a6315b91249 100644 --- a/drivers/infiniband/hw/cxgb4/provider.c +++ b/drivers/infiniband/hw/cxgb4/provider.c @@ -376,8 +376,9 @@ static int c4iw_query_port(struct ib_device *ibdev, u8 port, static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, - ibdev.dev); + struct ib_device *ibdev = rdma_device_to_ibdev(dev); + struct c4iw_dev *c4iw_dev = container_of(ibdev, struct c4iw_dev, ibdev); + pr_debug("dev 0x%p\n", dev); return sprintf(buf, "%d\n", CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type)); @@ -387,8 +388,8 @@ static DEVICE_ATTR_RO(hw_rev); static ssize_t hca_type_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, - ibdev.dev); + struct ib_device *ibdev = rdma_device_to_ibdev(dev); + struct c4iw_dev *c4iw_dev = container_of(ibdev, struct c4iw_dev, ibdev); struct ethtool_drvinfo info; struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0]; @@ -401,8 +402,9 @@ static DEVICE_ATTR_RO(hca_type); static ssize_t board_id_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, - ibdev.dev); + struct ib_device *ibdev = rdma_device_to_ibdev(dev); + struct c4iw_dev *c4iw_dev = container_of(ibdev, struct c4iw_dev, ibdev); + pr_debug("dev 0x%p\n", dev); return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor, c4iw_dev->rdev.lldi.pdev->device); diff --git a/drivers/infiniband/hw/hfi1/sysfs.c b/drivers/infiniband/hw/hfi1/sysfs.c index 2be513d4c9da..e36adc7834ed 100644 --- a/drivers/infiniband/hw/hfi1/sysfs.c +++ b/drivers/infiniband/hw/hfi1/sysfs.c @@ -497,8 +497,9 @@ static struct kobj_type hfi1_vl2mtu_ktype = { static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct hfi1_ibdev *dev = - container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct hfi1_ibdev, rdi.ibdev); return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev); } @@ -507,8 +508,9 @@ static DEVICE_ATTR_RO(hw_rev); static ssize_t board_id_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct hfi1_ibdev *dev = - container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct hfi1_ibdev, rdi.ibdev); struct hfi1_devdata *dd = dd_from_dev(dev); int ret; @@ -523,8 +525,9 @@ static DEVICE_ATTR_RO(board_id); static ssize_t boardversion_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct hfi1_ibdev *dev = - container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct hfi1_ibdev, rdi.ibdev); struct hfi1_devdata *dd = dd_from_dev(dev); /* The string printed here is already newline-terminated. */ @@ -535,8 +538,9 @@ static DEVICE_ATTR_RO(boardversion); static ssize_t nctxts_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct hfi1_ibdev *dev = - container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct hfi1_ibdev, rdi.ibdev); struct hfi1_devdata *dd = dd_from_dev(dev); /* @@ -554,8 +558,9 @@ static DEVICE_ATTR_RO(nctxts); static ssize_t nfreectxts_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct hfi1_ibdev *dev = - container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct hfi1_ibdev, rdi.ibdev); struct hfi1_devdata *dd = dd_from_dev(dev); /* Return the number of free user ports (contexts) available. */ @@ -566,8 +571,9 @@ static DEVICE_ATTR_RO(nfreectxts); static ssize_t serial_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct hfi1_ibdev *dev = - container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct hfi1_ibdev, rdi.ibdev); struct hfi1_devdata *dd = dd_from_dev(dev); return scnprintf(buf, PAGE_SIZE, "%s", dd->serial); @@ -578,8 +584,9 @@ static ssize_t chip_reset_store(struct device *device, struct device_attribute *attr, const char *buf, size_t count) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct hfi1_ibdev *dev = - container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct hfi1_ibdev, rdi.ibdev); struct hfi1_devdata *dd = dd_from_dev(dev); int ret; @@ -608,8 +615,9 @@ static DEVICE_ATTR_WO(chip_reset); static ssize_t tempsense_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct hfi1_ibdev *dev = - container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct hfi1_ibdev, rdi.ibdev); struct hfi1_devdata *dd = dd_from_dev(dev); struct hfi1_temp temp; int ret; diff --git a/drivers/infiniband/hw/i40iw/i40iw_verbs.c b/drivers/infiniband/hw/i40iw/i40iw_verbs.c index a773d1edf7fd..a193bcafe920 100644 --- a/drivers/infiniband/hw/i40iw/i40iw_verbs.c +++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c @@ -2140,9 +2140,10 @@ static int i40iw_dereg_mr(struct ib_mr *ib_mr) static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct i40iw_ib_device *iwibdev = container_of(dev, + struct ib_device *ibdev = rdma_device_to_ibdev(dev); + struct i40iw_ib_device *iwibdev = container_of(ibdev, struct i40iw_ib_device, - ibdev.dev); + ibdev); u32 hw_rev = iwibdev->iwdev->sc_dev.hw_rev; return sprintf(buf, "%x\n", hw_rev); diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index 0def2323459c..92aa3d0ee532 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -2042,8 +2042,9 @@ static int init_node_data(struct mlx4_ib_dev *dev) static ssize_t hca_type_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct mlx4_ib_dev *dev = - container_of(device, struct mlx4_ib_dev, ib_dev.dev); + container_of(ibdev, struct mlx4_ib_dev, ib_dev); return sprintf(buf, "MT%d\n", dev->dev->persist->pdev->device); } static DEVICE_ATTR_RO(hca_type); @@ -2051,8 +2052,9 @@ static DEVICE_ATTR_RO(hca_type); static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct mlx4_ib_dev *dev = - container_of(device, struct mlx4_ib_dev, ib_dev.dev); + container_of(ibdev, struct mlx4_ib_dev, ib_dev); return sprintf(buf, "%x\n", dev->dev->rev_id); } static DEVICE_ATTR_RO(hw_rev); @@ -2060,8 +2062,10 @@ static DEVICE_ATTR_RO(hw_rev); static ssize_t board_id_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct mlx4_ib_dev *dev = - container_of(device, struct mlx4_ib_dev, ib_dev.dev); + container_of(ibdev, struct mlx4_ib_dev, ib_dev); + return sprintf(buf, "%.*s\n", MLX4_BOARD_ID_LEN, dev->dev->board_id); } diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index b3986bc961ca..f8c89e371bab 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -4100,8 +4100,9 @@ static int init_node_data(struct mlx5_ib_dev *dev) static ssize_t fw_pages_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct mlx5_ib_dev *dev = - container_of(device, struct mlx5_ib_dev, ib_dev.dev); + container_of(ibdev, struct mlx5_ib_dev, ib_dev); return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); } @@ -4110,8 +4111,9 @@ static DEVICE_ATTR_RO(fw_pages); static ssize_t reg_pages_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct mlx5_ib_dev *dev = - container_of(device, struct mlx5_ib_dev, ib_dev.dev); + container_of(ibdev, struct mlx5_ib_dev, ib_dev); return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); } @@ -4120,8 +4122,10 @@ static DEVICE_ATTR_RO(reg_pages); static ssize_t hca_type_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct mlx5_ib_dev *dev = - container_of(device, struct mlx5_ib_dev, ib_dev.dev); + container_of(ibdev, struct mlx5_ib_dev, ib_dev); + return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); } static DEVICE_ATTR_RO(hca_type); @@ -4129,8 +4133,10 @@ static DEVICE_ATTR_RO(hca_type); static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct mlx5_ib_dev *dev = - container_of(device, struct mlx5_ib_dev, ib_dev.dev); + container_of(ibdev, struct mlx5_ib_dev, ib_dev); + return sprintf(buf, "%x\n", dev->mdev->rev_id); } static DEVICE_ATTR_RO(hw_rev); @@ -4138,8 +4144,10 @@ static DEVICE_ATTR_RO(hw_rev); static ssize_t board_id_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct mlx5_ib_dev *dev = - container_of(device, struct mlx5_ib_dev, ib_dev.dev); + container_of(ibdev, struct mlx5_ib_dev, ib_dev); + return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, dev->mdev->board_id); } diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c index 691c6f048938..61f5c89eab97 100644 --- a/drivers/infiniband/hw/mthca/mthca_provider.c +++ b/drivers/infiniband/hw/mthca/mthca_provider.c @@ -1079,8 +1079,10 @@ static int mthca_unmap_fmr(struct list_head *fmr_list) static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct mthca_dev *dev = - container_of(device, struct mthca_dev, ib_dev.dev); + container_of(ibdev, struct mthca_dev, ib_dev); + return sprintf(buf, "%x\n", dev->rev_id); } static DEVICE_ATTR_RO(hw_rev); @@ -1088,8 +1090,10 @@ static DEVICE_ATTR_RO(hw_rev); static ssize_t hca_type_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct mthca_dev *dev = - container_of(device, struct mthca_dev, ib_dev.dev); + container_of(ibdev, struct mthca_dev, ib_dev); + switch (dev->pdev->device) { case PCI_DEVICE_ID_MELLANOX_TAVOR: return sprintf(buf, "MT23108\n"); @@ -1109,8 +1113,10 @@ static DEVICE_ATTR_RO(hca_type); static ssize_t board_id_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct mthca_dev *dev = - container_of(device, struct mthca_dev, ib_dev.dev); + container_of(ibdev, struct mthca_dev, ib_dev); + return sprintf(buf, "%.*s\n", MTHCA_BOARD_ID_LEN, dev->board_id); } static DEVICE_ATTR_RO(board_id); diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c index 92d1cadd4cfd..791da2f35947 100644 --- a/drivers/infiniband/hw/nes/nes_verbs.c +++ b/drivers/infiniband/hw/nes/nes_verbs.c @@ -2559,8 +2559,9 @@ static int nes_dereg_mr(struct ib_mr *ib_mr) static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(dev); struct nes_ib_device *nesibdev = - container_of(dev, struct nes_ib_device, ibdev.dev); + container_of(ibdev, struct nes_ib_device, ibdev); struct nes_vnic *nesvnic = nesibdev->nesvnic; nes_debug(NES_DBG_INIT, "\n"); diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c index 873cc7f6fe61..94452ae12aff 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c @@ -118,7 +118,8 @@ static void get_dev_fw_str(struct ib_device *device, char *str) static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr, char *buf) { - struct ocrdma_dev *dev = dev_get_drvdata(device); + struct ib_device *ibdev = rdma_device_to_ibdev(device); + struct ocrdma_dev *dev = container_of(ibdev, struct ocrdma_dev, ibdev); return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->nic_info.pdev->vendor); } @@ -127,7 +128,8 @@ static DEVICE_ATTR_RO(hw_rev); static ssize_t hca_type_show(struct device *device, struct device_attribute *attr, char *buf) { - struct ocrdma_dev *dev = dev_get_drvdata(device); + struct ib_device *ibdev = rdma_device_to_ibdev(device); + struct ocrdma_dev *dev = container_of(ibdev, struct ocrdma_dev, ibdev); return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->model_number[0]); } diff --git a/drivers/infiniband/hw/qedr/main.c b/drivers/infiniband/hw/qedr/main.c index 8d6ff9df49fe..9e7223ff3f94 100644 --- a/drivers/infiniband/hw/qedr/main.c +++ b/drivers/infiniband/hw/qedr/main.c @@ -137,7 +137,8 @@ static int qedr_iw_port_immutable(struct ib_device *ibdev, u8 port_num, static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr, char *buf) { - struct qedr_dev *dev = dev_get_drvdata(device); + struct ib_device *ibdev = rdma_device_to_ibdev(device); + struct qedr_dev *dev = container_of(ibdev, struct qedr_dev, ibdev); return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->pdev->vendor); } diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/qib/qib_sysfs.c index 1cf4ca3f23e3..2226b787ce5d 100644 --- a/drivers/infiniband/hw/qib/qib_sysfs.c +++ b/drivers/infiniband/hw/qib/qib_sysfs.c @@ -554,8 +554,9 @@ static struct kobj_type qib_diagc_ktype = { static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct qib_ibdev *dev = - container_of(device, struct qib_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct qib_ibdev, rdi.ibdev); return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev); } @@ -564,8 +565,9 @@ static DEVICE_ATTR_RO(hw_rev); static ssize_t hca_type_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct qib_ibdev *dev = - container_of(device, struct qib_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct qib_ibdev, rdi.ibdev); struct qib_devdata *dd = dd_from_dev(dev); int ret; @@ -589,8 +591,9 @@ static DEVICE_ATTR_RO(version); static ssize_t boardversion_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct qib_ibdev *dev = - container_of(device, struct qib_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct qib_ibdev, rdi.ibdev); struct qib_devdata *dd = dd_from_dev(dev); /* The string printed here is already newline-terminated. */ @@ -601,8 +604,9 @@ static DEVICE_ATTR_RO(boardversion); static ssize_t localbus_info_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct qib_ibdev *dev = - container_of(device, struct qib_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct qib_ibdev, rdi.ibdev); struct qib_devdata *dd = dd_from_dev(dev); /* The string printed here is already newline-terminated. */ @@ -613,8 +617,9 @@ static DEVICE_ATTR_RO(localbus_info); static ssize_t nctxts_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct qib_ibdev *dev = - container_of(device, struct qib_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct qib_ibdev, rdi.ibdev); struct qib_devdata *dd = dd_from_dev(dev); /* Return the number of user ports (contexts) available. */ @@ -629,8 +634,9 @@ static DEVICE_ATTR_RO(nctxts); static ssize_t nfreectxts_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct qib_ibdev *dev = - container_of(device, struct qib_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct qib_ibdev, rdi.ibdev); struct qib_devdata *dd = dd_from_dev(dev); /* Return the number of free user ports (contexts) available. */ @@ -641,8 +647,9 @@ static DEVICE_ATTR_RO(nfreectxts); static ssize_t serial_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct qib_ibdev *dev = - container_of(device, struct qib_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct qib_ibdev, rdi.ibdev); struct qib_devdata *dd = dd_from_dev(dev); buf[sizeof(dd->serial)] = '\0'; @@ -656,8 +663,9 @@ static ssize_t chip_reset_store(struct device *device, struct device_attribute *attr, const char *buf, size_t count) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct qib_ibdev *dev = - container_of(device, struct qib_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct qib_ibdev, rdi.ibdev); struct qib_devdata *dd = dd_from_dev(dev); int ret; @@ -678,8 +686,9 @@ static DEVICE_ATTR_WO(chip_reset); static ssize_t tempsense_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ibdev = rdma_device_to_ibdev(device); struct qib_ibdev *dev = - container_of(device, struct qib_ibdev, rdi.ibdev.dev); + container_of(ibdev, struct qib_ibdev, rdi.ibdev); struct qib_devdata *dd = dd_from_dev(dev); int ret; int idx; diff --git a/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c b/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c index a7e4b2ccfaf8..826769d28ffe 100644 --- a/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c +++ b/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c @@ -49,8 +49,9 @@ static ssize_t board_id_show(struct device *device, struct device_attribute *attr, char *buf) { + struct ib_device *ib_dev = rdma_device_to_ibdev(device); struct usnic_ib_dev *us_ibdev = - container_of(device, struct usnic_ib_dev, ib_dev.dev); + container_of(ib_dev, struct usnic_ib_dev, ib_dev); unsigned short subsystem_device_id; mutex_lock(&us_ibdev->usdev_lock); @@ -67,14 +68,14 @@ static DEVICE_ATTR_RO(board_id); static ssize_t config_show(struct device *device, struct device_attribute *attr, char *buf) { - struct usnic_ib_dev *us_ibdev; + struct ib_device *ib_dev = rdma_device_to_ibdev(device); + struct usnic_ib_dev *us_ibdev = + container_of(ib_dev, struct usnic_ib_dev, ib_dev); char *ptr; unsigned left; unsigned n; enum usnic_vnic_res_type res_type; - us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev); - /* Buffer space limit is 1 page */ ptr = buf; left = PAGE_SIZE; @@ -130,7 +131,9 @@ static DEVICE_ATTR_RO(config); static ssize_t iface_show(struct device *device, struct device_attribute *attr, char *buf) { - struct usnic_ib_dev *us_ibdev; + struct ib_device *ib_dev = rdma_device_to_ibdev(device); + struct usnic_ib_dev *us_ibdev = + container_of(ib_dev, struct usnic_ib_dev, ib_dev); us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev); @@ -142,9 +145,9 @@ static DEVICE_ATTR_RO(iface); static ssize_t max_vf_show(struct device *device, struct device_attribute *attr, char *buf) { - struct usnic_ib_dev *us_ibdev; - - us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev); + struct ib_device *ib_dev = rdma_device_to_ibdev(device); + struct usnic_ib_dev *us_ibdev = + container_of(ib_dev, struct usnic_ib_dev, ib_dev); return scnprintf(buf, PAGE_SIZE, "%u\n", kref_read(&us_ibdev->vf_cnt)); @@ -154,10 +157,11 @@ static DEVICE_ATTR_RO(max_vf); static ssize_t qp_per_vf_show(struct device *device, struct device_attribute *attr, char *buf) { - struct usnic_ib_dev *us_ibdev; + struct ib_device *ib_dev = rdma_device_to_ibdev(device); + struct usnic_ib_dev *us_ibdev = + container_of(ib_dev, struct usnic_ib_dev, ib_dev); int qp_per_vf; - us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev); qp_per_vf = max(us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_WQ], us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_RQ]); @@ -169,9 +173,9 @@ static DEVICE_ATTR_RO(qp_per_vf); static ssize_t cq_per_vf_show(struct device *device, struct device_attribute *attr, char *buf) { - struct usnic_ib_dev *us_ibdev; - - us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev); + struct ib_device *ib_dev = rdma_device_to_ibdev(device); + struct usnic_ib_dev *us_ibdev = + container_of(ib_dev, struct usnic_ib_dev, ib_dev); return scnprintf(buf, PAGE_SIZE, "%d\n", us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_CQ]); diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c index 30817c79ba96..350e74bfbe2b 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.c +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c @@ -1148,8 +1148,8 @@ static int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) static ssize_t parent_show(struct device *device, struct device_attribute *attr, char *buf) { - struct rxe_dev *rxe = container_of(device, struct rxe_dev, - ib_dev.dev); + struct ib_device *ib_dev = rdma_device_to_ibdev(device); + struct rxe_dev *rxe = container_of(ib_dev, struct rxe_dev, ib_dev); return snprintf(buf, 16, "%s\n", rxe_parent_name(rxe, 1)); } diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index ba6e97432ad9..c7055e242792 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -4245,4 +4245,20 @@ rdma_set_device_sysfs_group(struct ib_device *dev, dev->groups[1] = group; } +/** + * rdma_device_to_ibdev - Get ib_device pointer from device pointer + * + * @device: device pointer for which ib_device pointer to retrieve + * + * rdma_device_to_ibdev() retrieves ib_device pointer from device. + * + * 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(). + */ +static inline struct ib_device *rdma_device_to_ibdev(struct device *device) +{ + return dev_get_drvdata(device); +} + #endif /* IB_VERBS_H */ -- 2.19.1