Add API rdma_query_hw_id() to enable kernel-mode applications to query the HW ID of the current device.
Signed-off-by: Chengchang Tang tangchengchang@huawei.com --- drivers/infiniband/hw/hns/hns_roce_ext.c | 21 +++++++++++++++++++++ drivers/infiniband/hw/hns/hns_roce_ext.h | 8 ++++++++ 2 files changed, 29 insertions(+)
diff --git a/drivers/infiniband/hw/hns/hns_roce_ext.c b/drivers/infiniband/hw/hns/hns_roce_ext.c index 0a89ba2..826f34e 100644 --- a/drivers/infiniband/hw/hns/hns_roce_ext.c +++ b/drivers/infiniband/hw/hns/hns_roce_ext.c @@ -70,3 +70,24 @@ u64 rdma_query_qp_db(struct ib_device *ib_dev, int qp_index) } EXPORT_SYMBOL(rdma_query_qp_db);
+int rdma_query_hw_id(struct ib_device *ib_dev, u32 *chip_id, + u32 *die_id, u32 *func_id) +{ + struct hns_roce_dev *hr_dev = to_hr_dev(ib_dev); + + if (!is_hns_roce(ib_dev) || is_hns_roce_vf(hr_dev)) + return -EOPNOTSUPP; + + if (!chip_id || !die_id || !func_id) + return -EINVAL; + + if (hr_dev->chip_id == HNS_IB_INVALID_ID) + return -EINVAL; + + *chip_id = hr_dev->chip_id; + *die_id = hr_dev->die_id; + *func_id = hr_dev->func_id; + return 0; +} +EXPORT_SYMBOL(rdma_query_hw_id); + diff --git a/drivers/infiniband/hw/hns/hns_roce_ext.h b/drivers/infiniband/hw/hns/hns_roce_ext.h index f9402b9..d80fdfc 100644 --- a/drivers/infiniband/hw/hns/hns_roce_ext.h +++ b/drivers/infiniband/hw/hns/hns_roce_ext.h @@ -32,4 +32,12 @@ bool rdma_support_stars(struct ib_device *ib_dev); */ u64 rdma_query_qp_db(struct ib_device *ib_dev, int qp_index);
+/** + * rdma_query_hw_id - Get the relevant hardware ID of the current device. + * @chip_id - The ID of the chip where the current device is located. + * @die_id - The ID of the IO DIE where the current device is located. + * @func_id - The function ID of this device. + */ +int rdma_query_hw_id(struct ib_device *ib_dev, u32 *chip_id, + u32 *die_id, u32 *func_id); #endif