Commit 54747231 authored by Parav Pandit's avatar Parav Pandit Committed by Jason Gunthorpe

RDMA: Introduce and use rdma_device_to_ibdev()

Introduce and use rdma_device_to_ibdev() API for those drivers which are
registering one sysfs group and also use in ib_core.

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: default avatarParav Pandit <parav@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent ea4baf7f
...@@ -296,8 +296,6 @@ struct ib_device *ib_alloc_device(size_t size) ...@@ -296,8 +296,6 @@ struct ib_device *ib_alloc_device(size_t size)
device->dev.class = &ib_class; device->dev.class = &ib_class;
device_initialize(&device->dev); device_initialize(&device->dev);
dev_set_drvdata(&device->dev, device);
INIT_LIST_HEAD(&device->event_handler_list); INIT_LIST_HEAD(&device->event_handler_list);
spin_lock_init(&device->event_handler_lock); spin_lock_init(&device->event_handler_lock);
rwlock_init(&device->client_data_lock); rwlock_init(&device->client_data_lock);
......
...@@ -1187,7 +1187,7 @@ static int add_port(struct ib_device *device, int port_num) ...@@ -1187,7 +1187,7 @@ static int add_port(struct ib_device *device, int port_num)
static ssize_t node_type_show(struct device *device, static ssize_t node_type_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct ib_device *dev = container_of(device, struct ib_device, dev); struct ib_device *dev = rdma_device_to_ibdev(device);
switch (dev->node_type) { switch (dev->node_type) {
case RDMA_NODE_IB_CA: return sprintf(buf, "%d: CA\n", dev->node_type); case RDMA_NODE_IB_CA: return sprintf(buf, "%d: CA\n", dev->node_type);
...@@ -1204,7 +1204,7 @@ static DEVICE_ATTR_RO(node_type); ...@@ -1204,7 +1204,7 @@ static DEVICE_ATTR_RO(node_type);
static ssize_t sys_image_guid_show(struct device *device, static ssize_t sys_image_guid_show(struct device *device,
struct device_attribute *dev_attr, char *buf) struct device_attribute *dev_attr, char *buf)
{ {
struct ib_device *dev = container_of(device, struct ib_device, dev); struct ib_device *dev = rdma_device_to_ibdev(device);
return sprintf(buf, "%04x:%04x:%04x:%04x\n", return sprintf(buf, "%04x:%04x:%04x:%04x\n",
be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[0]), be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[0]),
...@@ -1217,7 +1217,7 @@ static DEVICE_ATTR_RO(sys_image_guid); ...@@ -1217,7 +1217,7 @@ static DEVICE_ATTR_RO(sys_image_guid);
static ssize_t node_guid_show(struct device *device, static ssize_t node_guid_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct ib_device *dev = container_of(device, struct ib_device, dev); struct ib_device *dev = rdma_device_to_ibdev(device);
return sprintf(buf, "%04x:%04x:%04x:%04x\n", return sprintf(buf, "%04x:%04x:%04x:%04x\n",
be16_to_cpu(((__be16 *) &dev->node_guid)[0]), be16_to_cpu(((__be16 *) &dev->node_guid)[0]),
...@@ -1230,7 +1230,7 @@ static DEVICE_ATTR_RO(node_guid); ...@@ -1230,7 +1230,7 @@ static DEVICE_ATTR_RO(node_guid);
static ssize_t node_desc_show(struct device *device, static ssize_t node_desc_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct ib_device *dev = container_of(device, struct ib_device, dev); struct ib_device *dev = rdma_device_to_ibdev(device);
return sprintf(buf, "%.64s\n", dev->node_desc); return sprintf(buf, "%.64s\n", dev->node_desc);
} }
...@@ -1239,7 +1239,7 @@ static ssize_t node_desc_store(struct device *device, ...@@ -1239,7 +1239,7 @@ static ssize_t node_desc_store(struct device *device,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct ib_device *dev = container_of(device, struct ib_device, dev); struct ib_device *dev = rdma_device_to_ibdev(device);
struct ib_device_modify desc = {}; struct ib_device_modify desc = {};
int ret; int ret;
...@@ -1258,7 +1258,7 @@ static DEVICE_ATTR_RW(node_desc); ...@@ -1258,7 +1258,7 @@ static DEVICE_ATTR_RW(node_desc);
static ssize_t fw_ver_show(struct device *device, struct device_attribute *attr, static ssize_t fw_ver_show(struct device *device, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct ib_device *dev = container_of(device, struct ib_device, dev); struct ib_device *dev = rdma_device_to_ibdev(device);
ib_get_device_fw_str(dev, buf); ib_get_device_fw_str(dev, buf);
strlcat(buf, "\n", IB_FW_VERSION_NAME_MAX); strlcat(buf, "\n", IB_FW_VERSION_NAME_MAX);
......
...@@ -538,7 +538,8 @@ static struct bnxt_en_dev *bnxt_re_dev_probe(struct net_device *netdev) ...@@ -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, static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct bnxt_re_dev *rdev = to_bnxt_re_dev(device, ibdev.dev); struct bnxt_re_dev *rdev =
rdma_device_to_drv_device(device, struct bnxt_re_dev, ibdev);
return scnprintf(buf, PAGE_SIZE, "0x%x\n", rdev->en_dev->pdev->vendor); return scnprintf(buf, PAGE_SIZE, "0x%x\n", rdev->en_dev->pdev->vendor);
} }
...@@ -547,7 +548,8 @@ static DEVICE_ATTR_RO(hw_rev); ...@@ -547,7 +548,8 @@ static DEVICE_ATTR_RO(hw_rev);
static ssize_t hca_type_show(struct device *device, static ssize_t hca_type_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct bnxt_re_dev *rdev = to_bnxt_re_dev(device, ibdev.dev); struct bnxt_re_dev *rdev =
rdma_device_to_drv_device(device, struct bnxt_re_dev, ibdev);
return scnprintf(buf, PAGE_SIZE, "%s\n", rdev->ibdev.node_desc); return scnprintf(buf, PAGE_SIZE, "%s\n", rdev->ibdev.node_desc);
} }
......
...@@ -1130,8 +1130,9 @@ static int iwch_query_port(struct ib_device *ibdev, ...@@ -1130,8 +1130,9 @@ static int iwch_query_port(struct ib_device *ibdev,
static ssize_t hw_rev_show(struct device *dev, static ssize_t hw_rev_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct iwch_dev *iwch_dev = container_of(dev, struct iwch_dev, struct iwch_dev *iwch_dev =
ibdev.dev); rdma_device_to_drv_device(dev, struct iwch_dev, ibdev);
pr_debug("%s dev 0x%p\n", __func__, dev); pr_debug("%s dev 0x%p\n", __func__, dev);
return sprintf(buf, "%d\n", iwch_dev->rdev.t3cdev_p->type); return sprintf(buf, "%d\n", iwch_dev->rdev.t3cdev_p->type);
} }
...@@ -1140,8 +1141,8 @@ static DEVICE_ATTR_RO(hw_rev); ...@@ -1140,8 +1141,8 @@ static DEVICE_ATTR_RO(hw_rev);
static ssize_t hca_type_show(struct device *dev, static ssize_t hca_type_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct iwch_dev *iwch_dev = container_of(dev, struct iwch_dev, struct iwch_dev *iwch_dev =
ibdev.dev); rdma_device_to_drv_device(dev, struct iwch_dev, ibdev);
struct ethtool_drvinfo info; struct ethtool_drvinfo info;
struct net_device *lldev = iwch_dev->rdev.t3cdev_p->lldev; struct net_device *lldev = iwch_dev->rdev.t3cdev_p->lldev;
...@@ -1154,8 +1155,9 @@ static DEVICE_ATTR_RO(hca_type); ...@@ -1154,8 +1155,9 @@ static DEVICE_ATTR_RO(hca_type);
static ssize_t board_id_show(struct device *dev, static ssize_t board_id_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct iwch_dev *iwch_dev = container_of(dev, struct iwch_dev, struct iwch_dev *iwch_dev =
ibdev.dev); rdma_device_to_drv_device(dev, struct iwch_dev, ibdev);
pr_debug("%s dev 0x%p\n", __func__, dev); pr_debug("%s dev 0x%p\n", __func__, dev);
return sprintf(buf, "%x.%x\n", iwch_dev->rdev.rnic_info.pdev->vendor, return sprintf(buf, "%x.%x\n", iwch_dev->rdev.rnic_info.pdev->vendor,
iwch_dev->rdev.rnic_info.pdev->device); iwch_dev->rdev.rnic_info.pdev->device);
......
...@@ -376,8 +376,9 @@ static int c4iw_query_port(struct ib_device *ibdev, u8 port, ...@@ -376,8 +376,9 @@ static int c4iw_query_port(struct ib_device *ibdev, u8 port,
static ssize_t hw_rev_show(struct device *dev, static ssize_t hw_rev_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, struct c4iw_dev *c4iw_dev =
ibdev.dev); rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev);
pr_debug("dev 0x%p\n", dev); pr_debug("dev 0x%p\n", dev);
return sprintf(buf, "%d\n", return sprintf(buf, "%d\n",
CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type)); CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type));
...@@ -387,8 +388,8 @@ static DEVICE_ATTR_RO(hw_rev); ...@@ -387,8 +388,8 @@ static DEVICE_ATTR_RO(hw_rev);
static ssize_t hca_type_show(struct device *dev, static ssize_t hca_type_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, struct c4iw_dev *c4iw_dev =
ibdev.dev); rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev);
struct ethtool_drvinfo info; struct ethtool_drvinfo info;
struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0]; struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0];
...@@ -401,8 +402,9 @@ static DEVICE_ATTR_RO(hca_type); ...@@ -401,8 +402,9 @@ static DEVICE_ATTR_RO(hca_type);
static ssize_t board_id_show(struct device *dev, struct device_attribute *attr, static ssize_t board_id_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, struct c4iw_dev *c4iw_dev =
ibdev.dev); rdma_device_to_drv_device(dev, struct c4iw_dev, ibdev);
pr_debug("dev 0x%p\n", dev); pr_debug("dev 0x%p\n", dev);
return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor, return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor,
c4iw_dev->rdev.lldi.pdev->device); c4iw_dev->rdev.lldi.pdev->device);
......
...@@ -498,7 +498,7 @@ static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr, ...@@ -498,7 +498,7 @@ static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct hfi1_ibdev *dev = struct hfi1_ibdev *dev =
container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev); return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev);
} }
...@@ -508,7 +508,7 @@ static ssize_t board_id_show(struct device *device, ...@@ -508,7 +508,7 @@ static ssize_t board_id_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct hfi1_ibdev *dev = struct hfi1_ibdev *dev =
container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
struct hfi1_devdata *dd = dd_from_dev(dev); struct hfi1_devdata *dd = dd_from_dev(dev);
int ret; int ret;
...@@ -524,7 +524,7 @@ static ssize_t boardversion_show(struct device *device, ...@@ -524,7 +524,7 @@ static ssize_t boardversion_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct hfi1_ibdev *dev = struct hfi1_ibdev *dev =
container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
struct hfi1_devdata *dd = dd_from_dev(dev); struct hfi1_devdata *dd = dd_from_dev(dev);
/* The string printed here is already newline-terminated. */ /* The string printed here is already newline-terminated. */
...@@ -536,7 +536,7 @@ static ssize_t nctxts_show(struct device *device, ...@@ -536,7 +536,7 @@ static ssize_t nctxts_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct hfi1_ibdev *dev = struct hfi1_ibdev *dev =
container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
struct hfi1_devdata *dd = dd_from_dev(dev); struct hfi1_devdata *dd = dd_from_dev(dev);
/* /*
...@@ -555,7 +555,7 @@ static ssize_t nfreectxts_show(struct device *device, ...@@ -555,7 +555,7 @@ static ssize_t nfreectxts_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct hfi1_ibdev *dev = struct hfi1_ibdev *dev =
container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
struct hfi1_devdata *dd = dd_from_dev(dev); struct hfi1_devdata *dd = dd_from_dev(dev);
/* Return the number of free user ports (contexts) available. */ /* Return the number of free user ports (contexts) available. */
...@@ -567,7 +567,7 @@ static ssize_t serial_show(struct device *device, ...@@ -567,7 +567,7 @@ static ssize_t serial_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct hfi1_ibdev *dev = struct hfi1_ibdev *dev =
container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
struct hfi1_devdata *dd = dd_from_dev(dev); struct hfi1_devdata *dd = dd_from_dev(dev);
return scnprintf(buf, PAGE_SIZE, "%s", dd->serial); return scnprintf(buf, PAGE_SIZE, "%s", dd->serial);
...@@ -579,7 +579,7 @@ static ssize_t chip_reset_store(struct device *device, ...@@ -579,7 +579,7 @@ static ssize_t chip_reset_store(struct device *device,
size_t count) size_t count)
{ {
struct hfi1_ibdev *dev = struct hfi1_ibdev *dev =
container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
struct hfi1_devdata *dd = dd_from_dev(dev); struct hfi1_devdata *dd = dd_from_dev(dev);
int ret; int ret;
...@@ -609,7 +609,7 @@ static ssize_t tempsense_show(struct device *device, ...@@ -609,7 +609,7 @@ static ssize_t tempsense_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct hfi1_ibdev *dev = struct hfi1_ibdev *dev =
container_of(device, struct hfi1_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
struct hfi1_devdata *dd = dd_from_dev(dev); struct hfi1_devdata *dd = dd_from_dev(dev);
struct hfi1_temp temp; struct hfi1_temp temp;
int ret; int ret;
......
...@@ -2139,9 +2139,8 @@ static int i40iw_dereg_mr(struct ib_mr *ib_mr) ...@@ -2139,9 +2139,8 @@ static int i40iw_dereg_mr(struct ib_mr *ib_mr)
static ssize_t hw_rev_show(struct device *dev, static ssize_t hw_rev_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct i40iw_ib_device *iwibdev = container_of(dev, struct i40iw_ib_device *iwibdev =
struct i40iw_ib_device, rdma_device_to_drv_device(dev, struct i40iw_ib_device, ibdev);
ibdev.dev);
u32 hw_rev = iwibdev->iwdev->sc_dev.hw_rev; u32 hw_rev = iwibdev->iwdev->sc_dev.hw_rev;
return sprintf(buf, "%x\n", hw_rev); return sprintf(buf, "%x\n", hw_rev);
......
...@@ -2043,7 +2043,7 @@ static ssize_t hca_type_show(struct device *device, ...@@ -2043,7 +2043,7 @@ static ssize_t hca_type_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct mlx4_ib_dev *dev = struct mlx4_ib_dev *dev =
container_of(device, struct mlx4_ib_dev, ib_dev.dev); rdma_device_to_drv_device(device, struct mlx4_ib_dev, ib_dev);
return sprintf(buf, "MT%d\n", dev->dev->persist->pdev->device); return sprintf(buf, "MT%d\n", dev->dev->persist->pdev->device);
} }
static DEVICE_ATTR_RO(hca_type); static DEVICE_ATTR_RO(hca_type);
...@@ -2052,7 +2052,7 @@ static ssize_t hw_rev_show(struct device *device, ...@@ -2052,7 +2052,7 @@ static ssize_t hw_rev_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct mlx4_ib_dev *dev = struct mlx4_ib_dev *dev =
container_of(device, struct mlx4_ib_dev, ib_dev.dev); rdma_device_to_drv_device(device, struct mlx4_ib_dev, ib_dev);
return sprintf(buf, "%x\n", dev->dev->rev_id); return sprintf(buf, "%x\n", dev->dev->rev_id);
} }
static DEVICE_ATTR_RO(hw_rev); static DEVICE_ATTR_RO(hw_rev);
...@@ -2061,7 +2061,8 @@ static ssize_t board_id_show(struct device *device, ...@@ -2061,7 +2061,8 @@ static ssize_t board_id_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct mlx4_ib_dev *dev = struct mlx4_ib_dev *dev =
container_of(device, struct mlx4_ib_dev, ib_dev.dev); rdma_device_to_drv_device(device, struct mlx4_ib_dev, ib_dev);
return sprintf(buf, "%.*s\n", MLX4_BOARD_ID_LEN, return sprintf(buf, "%.*s\n", MLX4_BOARD_ID_LEN,
dev->dev->board_id); dev->dev->board_id);
} }
......
...@@ -4104,7 +4104,7 @@ static ssize_t fw_pages_show(struct device *device, ...@@ -4104,7 +4104,7 @@ static ssize_t fw_pages_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct mlx5_ib_dev *dev = struct mlx5_ib_dev *dev =
container_of(device, struct mlx5_ib_dev, ib_dev.dev); rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev);
return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages); return sprintf(buf, "%d\n", dev->mdev->priv.fw_pages);
} }
...@@ -4114,7 +4114,7 @@ static ssize_t reg_pages_show(struct device *device, ...@@ -4114,7 +4114,7 @@ static ssize_t reg_pages_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct mlx5_ib_dev *dev = struct mlx5_ib_dev *dev =
container_of(device, struct mlx5_ib_dev, ib_dev.dev); rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev);
return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages)); return sprintf(buf, "%d\n", atomic_read(&dev->mdev->priv.reg_pages));
} }
...@@ -4124,7 +4124,8 @@ static ssize_t hca_type_show(struct device *device, ...@@ -4124,7 +4124,8 @@ static ssize_t hca_type_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct mlx5_ib_dev *dev = struct mlx5_ib_dev *dev =
container_of(device, struct mlx5_ib_dev, ib_dev.dev); rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev);
return sprintf(buf, "MT%d\n", dev->mdev->pdev->device); return sprintf(buf, "MT%d\n", dev->mdev->pdev->device);
} }
static DEVICE_ATTR_RO(hca_type); static DEVICE_ATTR_RO(hca_type);
...@@ -4133,7 +4134,8 @@ static ssize_t hw_rev_show(struct device *device, ...@@ -4133,7 +4134,8 @@ static ssize_t hw_rev_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct mlx5_ib_dev *dev = struct mlx5_ib_dev *dev =
container_of(device, struct mlx5_ib_dev, ib_dev.dev); rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev);
return sprintf(buf, "%x\n", dev->mdev->rev_id); return sprintf(buf, "%x\n", dev->mdev->rev_id);
} }
static DEVICE_ATTR_RO(hw_rev); static DEVICE_ATTR_RO(hw_rev);
...@@ -4142,7 +4144,8 @@ static ssize_t board_id_show(struct device *device, ...@@ -4142,7 +4144,8 @@ static ssize_t board_id_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct mlx5_ib_dev *dev = struct mlx5_ib_dev *dev =
container_of(device, struct mlx5_ib_dev, ib_dev.dev); rdma_device_to_drv_device(device, struct mlx5_ib_dev, ib_dev);
return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN, return sprintf(buf, "%.*s\n", MLX5_BOARD_ID_LEN,
dev->mdev->board_id); dev->mdev->board_id);
} }
......
...@@ -1081,7 +1081,8 @@ static ssize_t hw_rev_show(struct device *device, ...@@ -1081,7 +1081,8 @@ static ssize_t hw_rev_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct mthca_dev *dev = struct mthca_dev *dev =
container_of(device, struct mthca_dev, ib_dev.dev); rdma_device_to_drv_device(device, struct mthca_dev, ib_dev);
return sprintf(buf, "%x\n", dev->rev_id); return sprintf(buf, "%x\n", dev->rev_id);
} }
static DEVICE_ATTR_RO(hw_rev); static DEVICE_ATTR_RO(hw_rev);
...@@ -1090,7 +1091,8 @@ static ssize_t hca_type_show(struct device *device, ...@@ -1090,7 +1091,8 @@ static ssize_t hca_type_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct mthca_dev *dev = struct mthca_dev *dev =
container_of(device, struct mthca_dev, ib_dev.dev); rdma_device_to_drv_device(device, struct mthca_dev, ib_dev);
switch (dev->pdev->device) { switch (dev->pdev->device) {
case PCI_DEVICE_ID_MELLANOX_TAVOR: case PCI_DEVICE_ID_MELLANOX_TAVOR:
return sprintf(buf, "MT23108\n"); return sprintf(buf, "MT23108\n");
...@@ -1111,7 +1113,8 @@ static ssize_t board_id_show(struct device *device, ...@@ -1111,7 +1113,8 @@ static ssize_t board_id_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct mthca_dev *dev = struct mthca_dev *dev =
container_of(device, struct mthca_dev, ib_dev.dev); rdma_device_to_drv_device(device, struct mthca_dev, ib_dev);
return sprintf(buf, "%.*s\n", MTHCA_BOARD_ID_LEN, dev->board_id); return sprintf(buf, "%.*s\n", MTHCA_BOARD_ID_LEN, dev->board_id);
} }
static DEVICE_ATTR_RO(board_id); static DEVICE_ATTR_RO(board_id);
......
...@@ -2560,7 +2560,7 @@ static ssize_t hw_rev_show(struct device *dev, ...@@ -2560,7 +2560,7 @@ static ssize_t hw_rev_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct nes_ib_device *nesibdev = struct nes_ib_device *nesibdev =
container_of(dev, struct nes_ib_device, ibdev.dev); rdma_device_to_drv_device(dev, struct nes_ib_device, ibdev);
struct nes_vnic *nesvnic = nesibdev->nesvnic; struct nes_vnic *nesvnic = nesibdev->nesvnic;
nes_debug(NES_DBG_INIT, "\n"); nes_debug(NES_DBG_INIT, "\n");
......
...@@ -118,7 +118,8 @@ static void get_dev_fw_str(struct ib_device *device, char *str) ...@@ -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, static ssize_t hw_rev_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct ocrdma_dev *dev = dev_get_drvdata(device); struct ocrdma_dev *dev =
rdma_device_to_drv_device(device, struct ocrdma_dev, ibdev);
return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->nic_info.pdev->vendor); return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->nic_info.pdev->vendor);
} }
...@@ -127,7 +128,8 @@ static DEVICE_ATTR_RO(hw_rev); ...@@ -127,7 +128,8 @@ static DEVICE_ATTR_RO(hw_rev);
static ssize_t hca_type_show(struct device *device, static ssize_t hca_type_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct ocrdma_dev *dev = dev_get_drvdata(device); struct ocrdma_dev *dev =
rdma_device_to_drv_device(device, struct ocrdma_dev, ibdev);
return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->model_number[0]); return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->model_number[0]);
} }
......
...@@ -137,7 +137,8 @@ static int qedr_iw_port_immutable(struct ib_device *ibdev, u8 port_num, ...@@ -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, static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct qedr_dev *dev = dev_get_drvdata(device); struct qedr_dev *dev =
rdma_device_to_drv_device(device, struct qedr_dev, ibdev);
return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->pdev->vendor); return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->pdev->vendor);
} }
......
...@@ -555,7 +555,7 @@ static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr, ...@@ -555,7 +555,7 @@ static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct qib_ibdev *dev = struct qib_ibdev *dev =
container_of(device, struct qib_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev); return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev);
} }
...@@ -565,7 +565,7 @@ static ssize_t hca_type_show(struct device *device, ...@@ -565,7 +565,7 @@ static ssize_t hca_type_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct qib_ibdev *dev = struct qib_ibdev *dev =
container_of(device, struct qib_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
struct qib_devdata *dd = dd_from_dev(dev); struct qib_devdata *dd = dd_from_dev(dev);
int ret; int ret;
...@@ -590,7 +590,7 @@ static ssize_t boardversion_show(struct device *device, ...@@ -590,7 +590,7 @@ static ssize_t boardversion_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct qib_ibdev *dev = struct qib_ibdev *dev =
container_of(device, struct qib_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
struct qib_devdata *dd = dd_from_dev(dev); struct qib_devdata *dd = dd_from_dev(dev);
/* The string printed here is already newline-terminated. */ /* The string printed here is already newline-terminated. */
...@@ -602,7 +602,7 @@ static ssize_t localbus_info_show(struct device *device, ...@@ -602,7 +602,7 @@ static ssize_t localbus_info_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct qib_ibdev *dev = struct qib_ibdev *dev =
container_of(device, struct qib_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
struct qib_devdata *dd = dd_from_dev(dev); struct qib_devdata *dd = dd_from_dev(dev);
/* The string printed here is already newline-terminated. */ /* The string printed here is already newline-terminated. */
...@@ -614,7 +614,7 @@ static ssize_t nctxts_show(struct device *device, ...@@ -614,7 +614,7 @@ static ssize_t nctxts_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct qib_ibdev *dev = struct qib_ibdev *dev =
container_of(device, struct qib_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
struct qib_devdata *dd = dd_from_dev(dev); struct qib_devdata *dd = dd_from_dev(dev);
/* Return the number of user ports (contexts) available. */ /* Return the number of user ports (contexts) available. */
...@@ -630,7 +630,7 @@ static ssize_t nfreectxts_show(struct device *device, ...@@ -630,7 +630,7 @@ static ssize_t nfreectxts_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct qib_ibdev *dev = struct qib_ibdev *dev =
container_of(device, struct qib_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
struct qib_devdata *dd = dd_from_dev(dev); struct qib_devdata *dd = dd_from_dev(dev);
/* Return the number of free user ports (contexts) available. */ /* Return the number of free user ports (contexts) available. */
...@@ -642,7 +642,7 @@ static ssize_t serial_show(struct device *device, ...@@ -642,7 +642,7 @@ static ssize_t serial_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct qib_ibdev *dev = struct qib_ibdev *dev =
container_of(device, struct qib_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
struct qib_devdata *dd = dd_from_dev(dev); struct qib_devdata *dd = dd_from_dev(dev);
buf[sizeof(dd->serial)] = '\0'; buf[sizeof(dd->serial)] = '\0';
...@@ -657,7 +657,7 @@ static ssize_t chip_reset_store(struct device *device, ...@@ -657,7 +657,7 @@ static ssize_t chip_reset_store(struct device *device,
size_t count) size_t count)
{ {
struct qib_ibdev *dev = struct qib_ibdev *dev =
container_of(device, struct qib_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
struct qib_devdata *dd = dd_from_dev(dev); struct qib_devdata *dd = dd_from_dev(dev);
int ret; int ret;
...@@ -679,7 +679,7 @@ static ssize_t tempsense_show(struct device *device, ...@@ -679,7 +679,7 @@ static ssize_t tempsense_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct qib_ibdev *dev = struct qib_ibdev *dev =
container_of(device, struct qib_ibdev, rdi.ibdev.dev); rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
struct qib_devdata *dd = dd_from_dev(dev); struct qib_devdata *dd = dd_from_dev(dev);
int ret; int ret;
int idx; int idx;
......
...@@ -50,7 +50,7 @@ static ssize_t board_id_show(struct device *device, ...@@ -50,7 +50,7 @@ static ssize_t board_id_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct usnic_ib_dev *us_ibdev = struct usnic_ib_dev *us_ibdev =
container_of(device, struct usnic_ib_dev, ib_dev.dev); rdma_device_to_drv_device(device, struct usnic_ib_dev, ib_dev);
unsigned short subsystem_device_id; unsigned short subsystem_device_id;
mutex_lock(&us_ibdev->usdev_lock); mutex_lock(&us_ibdev->usdev_lock);
...@@ -67,14 +67,13 @@ static DEVICE_ATTR_RO(board_id); ...@@ -67,14 +67,13 @@ static DEVICE_ATTR_RO(board_id);
static ssize_t static ssize_t
config_show(struct device *device, struct device_attribute *attr, char *buf) config_show(struct device *device, struct device_attribute *attr, char *buf)
{ {
struct usnic_ib_dev *us_ibdev; struct usnic_ib_dev *us_ibdev =
rdma_device_to_drv_device(device, struct usnic_ib_dev, ib_dev);
char *ptr; char *ptr;
unsigned left; unsigned left;
unsigned n; unsigned n;
enum usnic_vnic_res_type res_type; 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 */ /* Buffer space limit is 1 page */
ptr = buf; ptr = buf;
left = PAGE_SIZE; left = PAGE_SIZE;
...@@ -130,9 +129,8 @@ static DEVICE_ATTR_RO(config); ...@@ -130,9 +129,8 @@ static DEVICE_ATTR_RO(config);
static ssize_t static ssize_t
iface_show(struct device *device, struct device_attribute *attr, char *buf) iface_show(struct device *device, struct device_attribute *attr, char *buf)
{ {
struct usnic_ib_dev *us_ibdev; struct usnic_ib_dev *us_ibdev =
rdma_device_to_drv_device(device, struct usnic_ib_dev, ib_dev);
us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev);
return scnprintf(buf, PAGE_SIZE, "%s\n", return scnprintf(buf, PAGE_SIZE, "%s\n",
netdev_name(us_ibdev->netdev)); netdev_name(us_ibdev->netdev));
...@@ -142,9 +140,8 @@ static DEVICE_ATTR_RO(iface); ...@@ -142,9 +140,8 @@ static DEVICE_ATTR_RO(iface);
static ssize_t static ssize_t
max_vf_show(struct device *device, struct device_attribute *attr, char *buf) max_vf_show(struct device *device, struct device_attribute *attr, char *buf)
{ {
struct usnic_ib_dev *us_ibdev; struct usnic_ib_dev *us_ibdev =
rdma_device_to_drv_device(device, struct usnic_ib_dev, ib_dev);
us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev);
return scnprintf(buf, PAGE_SIZE, "%u\n", return scnprintf(buf, PAGE_SIZE, "%u\n",
kref_read(&us_ibdev->vf_cnt)); kref_read(&us_ibdev->vf_cnt));
...@@ -154,10 +151,10 @@ static DEVICE_ATTR_RO(max_vf); ...@@ -154,10 +151,10 @@ static DEVICE_ATTR_RO(max_vf);
static ssize_t static ssize_t
qp_per_vf_show(struct device *device, struct device_attribute *attr, char *buf) qp_per_vf_show(struct device *device, struct device_attribute *attr, char *buf)
{ {
struct usnic_ib_dev *us_ibdev; struct usnic_ib_dev *us_ibdev =
rdma_device_to_drv_device(device, struct usnic_ib_dev, ib_dev);
int qp_per_vf; 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], qp_per_vf = max(us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_WQ],
us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_RQ]); us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_RQ]);
...@@ -169,9 +166,8 @@ static DEVICE_ATTR_RO(qp_per_vf); ...@@ -169,9 +166,8 @@ static DEVICE_ATTR_RO(qp_per_vf);
static ssize_t static ssize_t
cq_per_vf_show(struct device *device, struct device_attribute *attr, char *buf) cq_per_vf_show(struct device *device, struct device_attribute *attr, char *buf)
{ {
struct usnic_ib_dev *us_ibdev; struct usnic_ib_dev *us_ibdev =
rdma_device_to_drv_device(device, struct usnic_ib_dev, ib_dev);
us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev);
return scnprintf(buf, PAGE_SIZE, "%d\n", return scnprintf(buf, PAGE_SIZE, "%d\n",
us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_CQ]); us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_CQ]);
......
...@@ -1129,8 +1129,8 @@ static int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) ...@@ -1129,8 +1129,8 @@ static int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid)
static ssize_t parent_show(struct device *device, static ssize_t parent_show(struct device *device,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct rxe_dev *rxe = container_of(device, struct rxe_dev, struct rxe_dev *rxe =
ib_dev.dev); rdma_device_to_drv_device(device, struct rxe_dev, ib_dev);
return snprintf(buf, 16, "%s\n", rxe_parent_name(rxe, 1)); return snprintf(buf, 16, "%s\n", rxe_parent_name(rxe, 1));
} }
......
...@@ -4241,4 +4241,27 @@ rdma_set_device_sysfs_group(struct ib_device *dev, ...@@ -4241,4 +4241,27 @@ rdma_set_device_sysfs_group(struct ib_device *dev,
dev->groups[1] = group; 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.
*
*/
static inline struct ib_device *rdma_device_to_ibdev(struct device *device)
{
return container_of(device, struct ib_device, dev);
}
/**
* rdma_device_to_drv_device - Helper macro to reach back to driver's
* ib_device holder structure from device pointer.
*
* 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().
*/
#define rdma_device_to_drv_device(dev, drv_dev_struct, ibdev_member) \
container_of(rdma_device_to_ibdev(dev), drv_dev_struct, ibdev_member)
#endif /* IB_VERBS_H */ #endif /* IB_VERBS_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment