Skip to content

Commit 07f06e0

Browse files
Junxian Huangrleon
authored andcommitted
RDMA/hns: Fix init failure of RoCE VF and HIP08
During device init, a struct for HW stats will be allocated. As HW stats are not supported for VF and HIP08, currently hns_roce_alloc_hw_port_stats() returns NULL in this case. However, ib-core considers the returned NULL pointer as memory allocation failure and returns ENOMEM, eventually leading to the failure of VF and HIP08 init. In the case where the driver does not support the .alloc_hw_port_stats() ops, ib-core will return EOPNOTSUPP and ignore this error code in the upper layer function. So for VF and HIP08, just don't set the HW stats ops to ib-core. Fixes: 5a87279 ("RDMA/hns: Support hns HW stats") Signed-off-by: Junxian Huang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Leon Romanovsky <[email protected]>
1 parent b4a797b commit 07f06e0

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

drivers/infiniband/hw/hns/hns_roce_main.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,6 @@ static struct rdma_hw_stats *hns_roce_alloc_hw_port_stats(
553553
return NULL;
554554
}
555555

556-
if (hr_dev->pci_dev->revision <= PCI_REVISION_ID_HIP08 ||
557-
hr_dev->is_vf)
558-
return NULL;
559-
560556
return rdma_alloc_hw_stats_struct(hns_roce_port_stats_descs,
561557
ARRAY_SIZE(hns_roce_port_stats_descs),
562558
RDMA_HW_STATS_DEFAULT_LIFESPAN);
@@ -576,10 +572,6 @@ static int hns_roce_get_hw_stats(struct ib_device *device,
576572
if (port > hr_dev->caps.num_ports)
577573
return -EINVAL;
578574

579-
if (hr_dev->pci_dev->revision <= PCI_REVISION_ID_HIP08 ||
580-
hr_dev->is_vf)
581-
return -EOPNOTSUPP;
582-
583575
ret = hr_dev->hw->query_hw_counter(hr_dev, stats->value, port,
584576
&num_counters);
585577
if (ret) {
@@ -633,8 +625,6 @@ static const struct ib_device_ops hns_roce_dev_ops = {
633625
.query_pkey = hns_roce_query_pkey,
634626
.query_port = hns_roce_query_port,
635627
.reg_user_mr = hns_roce_reg_user_mr,
636-
.alloc_hw_port_stats = hns_roce_alloc_hw_port_stats,
637-
.get_hw_stats = hns_roce_get_hw_stats,
638628

639629
INIT_RDMA_OBJ_SIZE(ib_ah, hns_roce_ah, ibah),
640630
INIT_RDMA_OBJ_SIZE(ib_cq, hns_roce_cq, ib_cq),
@@ -643,6 +633,11 @@ static const struct ib_device_ops hns_roce_dev_ops = {
643633
INIT_RDMA_OBJ_SIZE(ib_ucontext, hns_roce_ucontext, ibucontext),
644634
};
645635

636+
static const struct ib_device_ops hns_roce_dev_hw_stats_ops = {
637+
.alloc_hw_port_stats = hns_roce_alloc_hw_port_stats,
638+
.get_hw_stats = hns_roce_get_hw_stats,
639+
};
640+
646641
static const struct ib_device_ops hns_roce_dev_mr_ops = {
647642
.rereg_user_mr = hns_roce_rereg_user_mr,
648643
};
@@ -721,6 +716,10 @@ static int hns_roce_register_device(struct hns_roce_dev *hr_dev)
721716
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC)
722717
ib_set_device_ops(ib_dev, &hns_roce_dev_xrcd_ops);
723718

719+
if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09 &&
720+
!hr_dev->is_vf)
721+
ib_set_device_ops(ib_dev, &hns_roce_dev_hw_stats_ops);
722+
724723
ib_set_device_ops(ib_dev, hr_dev->hw->hns_roce_dev_ops);
725724
ib_set_device_ops(ib_dev, &hns_roce_dev_ops);
726725
ib_set_device_ops(ib_dev, &hns_roce_dev_restrack_ops);

0 commit comments

Comments
 (0)