Support SW stats with debugfs.
Juan Zhou (2): Revert "RDMA/hns: Fix missing dealloc_dfx_cnt() during device unregister" Revert "RDMA/hns: Add dfx cnt stats"
Junxian Huang (4): RDMA/hns: Fix an inappropriate err code for unsupported operations RDMA/hns: Support SW stats with debugfs RDMA/hns: Remove return value checks of debugfs functions RDMA/hns: Don't set the HW stats ops for VF and HIP08
drivers/infiniband/hw/hns/hns_roce_cq.c | 6 +- drivers/infiniband/hw/hns/hns_roce_debugfs.c | 95 +++++++++++++++----- drivers/infiniband/hw/hns/hns_roce_device.h | 4 +- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 35 +++++--- drivers/infiniband/hw/hns/hns_roce_main.c | 70 +++++---------- drivers/infiniband/hw/hns/hns_roce_pd.c | 2 +- 6 files changed, 121 insertions(+), 91 deletions(-)
-- 2.30.0
From: Juan Zhou zhoujuan51@h-partners.com
driver inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8EX1J
--------------------------------------------------------------------------
This reverts commit de8a9a4fafb585f89de338d5ecb95e755c8d6f31.
Signed-off-by: Juan Zhou zhoujuan51@h-partners.com --- drivers/infiniband/hw/hns/hns_roce_main.c | 1 - 1 file changed, 1 deletion(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c index 239e08abd166..9d67d8e801ce 100644 --- a/drivers/infiniband/hw/hns/hns_roce_main.c +++ b/drivers/infiniband/hw/hns/hns_roce_main.c @@ -1593,7 +1593,6 @@ void hns_roce_exit(struct hns_roce_dev *hr_dev, bool bond_cleanup) hns_roce_cmd_cleanup(hr_dev); if (hr_dev->hw->cmq_exit) hr_dev->hw->cmq_exit(hr_dev); - hns_roce_dealloc_dfx_cnt(hr_dev); if (hr_dev->notify_tbl) kvfree(hr_dev->notify_tbl); }
From: Juan Zhou zhoujuan51@h-partners.com
driver inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8EX1J
--------------------------------------------------------------------------
This reverts commit d5a4ca75e7ca2ea363ff5a0fa719433d0de92578.
Signed-off-by: Juan Zhou zhoujuan51@h-partners.com --- drivers/infiniband/hw/hns/hns_roce_ah.c | 8 +- drivers/infiniband/hw/hns/hns_roce_cmd.c | 17 +--- drivers/infiniband/hw/hns/hns_roce_cq.c | 19 ++--- drivers/infiniband/hw/hns/hns_roce_device.h | 22 ----- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 7 -- drivers/infiniband/hw/hns/hns_roce_main.c | 92 ++++----------------- drivers/infiniband/hw/hns/hns_roce_mr.c | 22 ++--- drivers/infiniband/hw/hns/hns_roce_pd.c | 10 +-- drivers/infiniband/hw/hns/hns_roce_qp.c | 16 +--- drivers/infiniband/hw/hns/hns_roce_srq.c | 7 +- 10 files changed, 46 insertions(+), 174 deletions(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_ah.c b/drivers/infiniband/hw/hns/hns_roce_ah.c index f4ceaeba5601..4404b45c5ab1 100644 --- a/drivers/infiniband/hw/hns/hns_roce_ah.c +++ b/drivers/infiniband/hw/hns/hns_roce_ah.c @@ -84,7 +84,7 @@ int hns_roce_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr, ret = 0;
if (ret && grh->sgid_attr->gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) - goto err_out; + return ret;
if (tc_mode == HNAE3_TC_MAP_MODE_DSCP && grh->sgid_attr->gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) @@ -100,7 +100,7 @@ int hns_roce_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr, ret = rdma_read_gid_l2_fields(ah_attr->grh.sgid_attr, &ah->av.vlan_id, NULL); if (ret) - goto err_out; + return ret;
ah->av.vlan_en = ah->av.vlan_id < VLAN_N_VID; } @@ -112,10 +112,6 @@ int hns_roce_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr, min(udata->outlen, sizeof(resp))); }
-err_out: - if (ret) - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_AH_CREATE_ERR_CNT]); - return ret; }
diff --git a/drivers/infiniband/hw/hns/hns_roce_cmd.c b/drivers/infiniband/hw/hns/hns_roce_cmd.c index a269578c8d89..864413607571 100644 --- a/drivers/infiniband/hw/hns/hns_roce_cmd.c +++ b/drivers/infiniband/hw/hns/hns_roce_cmd.c @@ -41,14 +41,7 @@ static int hns_roce_cmd_mbox_post_hw(struct hns_roce_dev *hr_dev, struct hns_roce_mbox_msg *mbox_msg) { - int ret; - - ret = hr_dev->hw->post_mbox(hr_dev, mbox_msg); - if (ret) - return ret; - - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MBX_POSTED_CNT]); - return 0; + return hr_dev->hw->post_mbox(hr_dev, mbox_msg); }
/* this should be called with "poll_sem" */ @@ -65,12 +58,7 @@ static int __hns_roce_cmd_mbox_poll(struct hns_roce_dev *hr_dev, return ret; }
- ret = hr_dev->hw->poll_mbox_done(hr_dev); - if (ret) - return ret; - - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MBX_POLLED_CNT]); - return 0; + return hr_dev->hw->poll_mbox_done(hr_dev); }
static int hns_roce_cmd_mbox_poll(struct hns_roce_dev *hr_dev, @@ -101,7 +89,6 @@ void hns_roce_cmd_event(struct hns_roce_dev *hr_dev, u16 token, u8 status, context->result = (status == HNS_ROCE_CMD_SUCCESS) ? 0 : (-EIO); context->out_param = out_param; complete(&context->done); - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MBX_EVENT_CNT]); }
static int __hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, diff --git a/drivers/infiniband/hw/hns/hns_roce_cq.c b/drivers/infiniband/hw/hns/hns_roce_cq.c index 1858b0726c9f..2d6f8c55e2b5 100644 --- a/drivers/infiniband/hw/hns/hns_roce_cq.c +++ b/drivers/infiniband/hw/hns/hns_roce_cq.c @@ -466,34 +466,32 @@ int hns_roce_create_cq(struct ib_cq *ib_cq, const struct ib_cq_init_attr *attr, struct hns_roce_ib_create_cq ucmd = {}; int ret;
- if (attr->flags) { - ret = -EOPNOTSUPP; - goto err_out; - } + if (attr->flags) + return -EOPNOTSUPP;
ret = verify_cq_create_attr(hr_dev, attr); if (ret) - goto err_out; + return ret;
if (udata) { ret = get_cq_ucmd(hr_cq, udata, &ucmd); if (ret) - goto err_out; + return ret;
}
ret = set_cq_param(hr_cq, attr->cqe, attr->comp_vector, &ucmd); if (ret) - goto err_out; + return ret;
ret = set_cqe_size(hr_cq, udata, &ucmd); if (ret) - goto err_out; + return ret;
ret = alloc_cq_buf(hr_dev, hr_cq, udata, ucmd.buf_addr); if (ret) { ibdev_err(ibdev, "failed to alloc CQ buf, ret = %d.\n", ret); - goto err_out; + return ret; }
ret = alloc_cq_db(hr_dev, hr_cq, udata, ucmd.db_addr, &resp); @@ -541,9 +539,6 @@ int hns_roce_create_cq(struct ib_cq *ib_cq, const struct ib_cq_init_attr *attr, free_cq_db(hr_dev, hr_cq, udata); err_cq_buf: free_cq_buf(hr_dev, hr_cq); -err_out: - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_CQ_CREATE_ERR_CNT]); - return ret; }
diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h index 146eafaec5bf..010463d5caa2 100644 --- a/drivers/infiniband/hw/hns/hns_roce_device.h +++ b/drivers/infiniband/hw/hns/hns_roce_device.h @@ -994,27 +994,6 @@ enum hns_roce_hw_pkt_stat_index { HNS_ROCE_HW_CNT_TOTAL, };
-enum hns_roce_hw_dfx_stat_index { - HNS_ROCE_DFX_AEQE_CNT, - HNS_ROCE_DFX_CEQE_CNT, - HNS_ROCE_DFX_CMDS_CNT, - HNS_ROCE_DFX_CMDS_ERR_CNT, - HNS_ROCE_DFX_MBX_POSTED_CNT, - HNS_ROCE_DFX_MBX_POLLED_CNT, - HNS_ROCE_DFX_MBX_EVENT_CNT, - HNS_ROCE_DFX_QP_CREATE_ERR_CNT, - HNS_ROCE_DFX_QP_MODIFY_ERR_CNT, - HNS_ROCE_DFX_CQ_CREATE_ERR_CNT, - HNS_ROCE_DFX_SRQ_CREATE_ERR_CNT, - HNS_ROCE_DFX_XRCD_ALLOC_ERR_CNT, - HNS_ROCE_DFX_MR_REG_ERR_CNT, - HNS_ROCE_DFX_MR_REREG_ERR_CNT, - HNS_ROCE_DFX_AH_CREATE_ERR_CNT, - HNS_ROCE_DFX_MMAP_ERR_CNT, - HNS_ROCE_DFX_UCTX_ALLOC_ERR_CNT, - HNS_ROCE_DFX_CNT_TOTAL -}; - struct hns_roce_hw { int (*cmq_init)(struct hns_roce_dev *hr_dev); void (*cmq_exit)(struct hns_roce_dev *hr_dev); @@ -1174,7 +1153,6 @@ struct hns_roce_dev {
struct notifier_block bond_nb; struct hns_roce_port port_data[HNS_ROCE_MAX_PORTS]; - atomic64_t *dfx_cnt; struct hns_roce_poe_ctx poe_ctx; /* poe ch array */
struct rdma_notify_mem *notify_tbl; diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 3702d866bc02..12ebe93ff9fb 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -1416,8 +1416,6 @@ static int __hns_roce_cmq_send(struct hns_roce_dev *hr_dev, /* Write to hardware */ roce_write(hr_dev, ROCEE_TX_CMQ_PI_REG, csq->head);
- atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_CMDS_CNT]); - do { if (hns_roce_cmq_csq_done(hr_dev)) break; @@ -1457,9 +1455,6 @@ static int __hns_roce_cmq_send(struct hns_roce_dev *hr_dev,
spin_unlock_bh(&csq->lock);
- if (ret) - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_CMDS_ERR_CNT]); - return ret; }
@@ -6532,7 +6527,6 @@ static irqreturn_t hns_roce_v2_aeq_int(struct hns_roce_dev *hr_dev, eq->sub_type = sub_type; ++eq->cons_index; aeqe_found = IRQ_HANDLED; - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_AEQE_CNT]);
hns_roce_v2_init_irq_work(hr_dev, eq, queue_num);
@@ -6575,7 +6569,6 @@ static irqreturn_t hns_roce_v2_ceq_int(struct hns_roce_dev *hr_dev,
++eq->cons_index; ceqe_found = IRQ_HANDLED; - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_CEQE_CNT]);
ceqe = next_ceqe_sw_v2(eq); } diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c index 9d67d8e801ce..f9e304296cf0 100644 --- a/drivers/infiniband/hw/hns/hns_roce_main.c +++ b/drivers/infiniband/hw/hns/hns_roce_main.c @@ -569,10 +569,10 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx, struct hns_roce_dev *hr_dev = to_hr_dev(uctx->device); struct hns_roce_ib_alloc_ucontext_resp resp = {}; struct hns_roce_ib_alloc_ucontext ucmd = {}; - int ret = -EAGAIN; + int ret;
if (!hr_dev->active) - goto error_fail_uar_alloc; + return -EAGAIN;
context->pid = current->pid; INIT_LIST_HEAD(&context->list); @@ -580,7 +580,7 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx, ret = ib_copy_from_udata(&ucmd, udata, min(udata->inlen, sizeof(ucmd))); if (ret) - goto error_fail_uar_alloc; + return ret;
hns_roce_get_uctx_config(hr_dev, context, &ucmd, &resp);
@@ -629,8 +629,6 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx, ida_free(&hr_dev->uar_ida.ida, (int)context->uar.logic_idx);
error_fail_uar_alloc: - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_UCTX_ALLOC_ERR_CNT]); - return ret; }
@@ -693,10 +691,8 @@ static int hns_roce_mmap(struct ib_ucontext *uctx, struct vm_area_struct *vma) int ret;
rdma_entry = rdma_user_mmap_entry_get_pgoff(uctx, vma->vm_pgoff); - if (!rdma_entry) { - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MMAP_ERR_CNT]); + if (!rdma_entry) return -EINVAL; - }
entry = to_hns_mmap(rdma_entry); pfn = entry->address >> PAGE_SHIFT; @@ -728,8 +724,6 @@ static int hns_roce_mmap(struct ib_ucontext *uctx, struct vm_area_struct *vma)
out: rdma_user_mmap_entry_put(rdma_entry); - if (ret) - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MMAP_ERR_CNT]);
return ret; } @@ -786,30 +780,10 @@ static void hns_roce_get_fw_ver(struct ib_device *device, char *str) sub_minor); }
-#define HNS_ROCE_DFX_STATS(ename, cname) \ - [HNS_ROCE_DFX_##ename##_CNT] = cname - #define HNS_ROCE_HW_CNT(ename, cname) \ - [HNS_ROCE_DFX_CNT_TOTAL + HNS_ROCE_HW_##ename##_CNT] = cname + [HNS_ROCE_HW_##ename##_CNT] = cname
static const char *const hns_roce_port_stats_descs[] = { - HNS_ROCE_DFX_STATS(AEQE, "aeqe"), - HNS_ROCE_DFX_STATS(CEQE, "ceqe"), - HNS_ROCE_DFX_STATS(CMDS, "cmds"), - HNS_ROCE_DFX_STATS(CMDS_ERR, "cmds_err"), - HNS_ROCE_DFX_STATS(MBX_POSTED, "posted_mbx"), - HNS_ROCE_DFX_STATS(MBX_POLLED, "polled_mbx"), - HNS_ROCE_DFX_STATS(MBX_EVENT, "mbx_event"), - HNS_ROCE_DFX_STATS(QP_CREATE_ERR, "qp_create_err"), - HNS_ROCE_DFX_STATS(QP_MODIFY_ERR, "qp_modify_err"), - HNS_ROCE_DFX_STATS(CQ_CREATE_ERR, "cq_create_err"), - HNS_ROCE_DFX_STATS(SRQ_CREATE_ERR, "srq_create_err"), - HNS_ROCE_DFX_STATS(XRCD_ALLOC_ERR, "xrcd_alloc_err"), - HNS_ROCE_DFX_STATS(MR_REG_ERR, "mr_reg_err"), - HNS_ROCE_DFX_STATS(MR_REREG_ERR, "mr_rereg_err"), - HNS_ROCE_DFX_STATS(AH_CREATE_ERR, "ah_create_err"), - HNS_ROCE_DFX_STATS(MMAP_ERR, "mmap_err"), - HNS_ROCE_DFX_STATS(UCTX_ALLOC_ERR, "uctx_alloc_err"), HNS_ROCE_HW_CNT(RX_RC_PKT, "rx_rc_pkt"), HNS_ROCE_HW_CNT(RX_UC_PKT, "rx_uc_pkt"), HNS_ROCE_HW_CNT(RX_UD_PKT, "rx_ud_pkt"), @@ -838,21 +812,19 @@ static struct rdma_hw_stats *hns_roce_alloc_hw_port_stats(struct ib_device *devi u8 port_num) { struct hns_roce_dev *hr_dev = to_hr_dev(device); - int num_counters; + u32 port = port_num - 1;
- if (port_num > hr_dev->caps.num_ports) { + if (hr_dev->pci_dev->revision <= PCI_REVISION_ID_HIP08 || + hr_dev->is_vf) + return NULL; + + if (port > hr_dev->caps.num_ports) { ibdev_err(device, "invalid port num.\n"); return NULL; }
- if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09 && - !hr_dev->is_vf) - num_counters = ARRAY_SIZE(hns_roce_port_stats_descs); - else - num_counters = HNS_ROCE_DFX_CNT_TOTAL; - return rdma_alloc_hw_stats_struct(hns_roce_port_stats_descs, - num_counters, + ARRAY_SIZE(hns_roce_port_stats_descs), RDMA_HW_STATS_DEFAULT_LIFESPAN); }
@@ -861,9 +833,8 @@ static int hns_roce_get_hw_stats(struct ib_device *device, u8 port, int index) { struct hns_roce_dev *hr_dev = to_hr_dev(device); - int hw_counters = HNS_ROCE_HW_CNT_TOTAL; + int num_counters = HNS_ROCE_HW_CNT_TOTAL; int ret; - int i;
if (port == 0) return 0; @@ -871,24 +842,19 @@ static int hns_roce_get_hw_stats(struct ib_device *device, if (port > hr_dev->caps.num_ports) return -EINVAL;
- for (i = 0; i < HNS_ROCE_DFX_CNT_TOTAL; i++) - stats->value[i] = atomic64_read(&hr_dev->dfx_cnt[i]); - if (hr_dev->pci_dev->revision <= PCI_REVISION_ID_HIP08 || hr_dev->is_vf) - return HNS_ROCE_DFX_CNT_TOTAL; + return -EOPNOTSUPP;
- hw_counters = HNS_ROCE_HW_CNT_TOTAL; - ret = hr_dev->hw->query_hw_counter(hr_dev, - &stats->value[HNS_ROCE_DFX_CNT_TOTAL], - port, &hw_counters); + ret = hr_dev->hw->query_hw_counter(hr_dev, stats->value, port, + &num_counters); if (ret) { ibdev_err(device, "failed to query hw counter, ret = %d.\n", ret); return ret; }
- return hw_counters + HNS_ROCE_DFX_CNT_TOTAL; + return num_counters; }
static void hns_roce_unregister_device(struct hns_roce_dev *hr_dev, @@ -1457,21 +1423,6 @@ static void hns_roce_unregister_poe_ch(struct hns_roce_dev *hr_dev) kvfree(hr_dev->poe_ctx.poe_ch); }
-static int hns_roce_alloc_dfx_cnt(struct hns_roce_dev *hr_dev) -{ - hr_dev->dfx_cnt = kcalloc(HNS_ROCE_DFX_CNT_TOTAL, sizeof(atomic64_t), - GFP_KERNEL); - if (!hr_dev->dfx_cnt) - return -ENOMEM; - - return 0; -} - -static void hns_roce_dealloc_dfx_cnt(struct hns_roce_dev *hr_dev) -{ - kfree(hr_dev->dfx_cnt); -} - int hns_roce_init(struct hns_roce_dev *hr_dev) { struct device *dev = hr_dev->dev; @@ -1479,15 +1430,11 @@ int hns_roce_init(struct hns_roce_dev *hr_dev)
hr_dev->is_reset = false;
- ret = hns_roce_alloc_dfx_cnt(hr_dev); - if (ret) - return ret; - if (hr_dev->hw->cmq_init) { ret = hr_dev->hw->cmq_init(hr_dev); if (ret) { dev_err(dev, "Init RoCE Command Queue failed!\n"); - goto error_failed_alloc_dfx_cnt; + return ret; } }
@@ -1568,9 +1515,6 @@ int hns_roce_init(struct hns_roce_dev *hr_dev) if (hr_dev->hw->cmq_exit) hr_dev->hw->cmq_exit(hr_dev);
-error_failed_alloc_dfx_cnt: - hns_roce_dealloc_dfx_cnt(hr_dev); - return ret; }
diff --git a/drivers/infiniband/hw/hns/hns_roce_mr.c b/drivers/infiniband/hw/hns/hns_roce_mr.c index 0b5108d79219..a2f07a5f9501 100644 --- a/drivers/infiniband/hw/hns/hns_roce_mr.c +++ b/drivers/infiniband/hw/hns/hns_roce_mr.c @@ -235,10 +235,8 @@ struct ib_mr *hns_roce_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, int ret;
mr = kzalloc(sizeof(*mr), GFP_KERNEL); - if (!mr) { - ret = -ENOMEM; - goto err_out; - } + if (!mr) + return ERR_PTR(-ENOMEM);
mr->iova = virt_addr; mr->size = length; @@ -268,9 +266,6 @@ struct ib_mr *hns_roce_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, free_mr_key(hr_dev, mr); err_alloc_mr: kfree(mr); -err_out: - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MR_REG_ERR_CNT]); - return ERR_PTR(ret); }
@@ -285,15 +280,12 @@ int hns_roce_rereg_user_mr(struct ib_mr *ibmr, int flags, u64 start, u64 length, unsigned long mtpt_idx; int ret;
- if (!mr->enabled) { - ret = -EINVAL; - goto err_out; - } + if (!mr->enabled) + return -EINVAL;
mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); - ret = PTR_ERR_OR_ZERO(mailbox); - if (ret) - goto err_out; + if (IS_ERR(mailbox)) + return PTR_ERR(mailbox);
mtpt_idx = key_to_hw_index(mr->key) & (hr_dev->caps.num_mtpts - 1); ret = hns_roce_cmd_mbox(hr_dev, 0, mailbox->dma, HNS_ROCE_CMD_QUERY_MPT, @@ -343,8 +335,6 @@ int hns_roce_rereg_user_mr(struct ib_mr *ibmr, int flags, u64 start, u64 length,
free_cmd_mbox: hns_roce_free_cmd_mailbox(hr_dev, mailbox); -err_out: - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MR_REREG_ERR_CNT]);
return ret; } diff --git a/drivers/infiniband/hw/hns/hns_roce_pd.c b/drivers/infiniband/hw/hns/hns_roce_pd.c index 6c69e095aa01..a720801eaac9 100644 --- a/drivers/infiniband/hw/hns/hns_roce_pd.c +++ b/drivers/infiniband/hw/hns/hns_roce_pd.c @@ -146,18 +146,16 @@ int hns_roce_alloc_xrcd(struct ib_xrcd *ib_xrcd, struct ib_udata *udata) { struct hns_roce_dev *hr_dev = to_hr_dev(ib_xrcd->device); struct hns_roce_xrcd *xrcd = to_hr_xrcd(ib_xrcd); - int ret = -EINVAL; + int ret;
if (!(hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC)) - goto err_out; + return -EINVAL;
ret = hns_roce_xrcd_alloc(hr_dev, &xrcd->xrcdn); - -err_out: if (ret) - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_XRCD_ALLOC_ERR_CNT]); + return ret;
- return ret; + return 0; }
int hns_roce_dealloc_xrcd(struct ib_xrcd *ib_xrcd, struct ib_udata *udata) diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c index e8e5641ec692..b1a102970d71 100644 --- a/drivers/infiniband/hw/hns/hns_roce_qp.c +++ b/drivers/infiniband/hw/hns/hns_roce_qp.c @@ -1417,13 +1417,11 @@ struct ib_qp *hns_roce_create_qp(struct ib_pd *pd,
ret = check_qp_type(hr_dev, init_attr->qp_type, !!udata); if (ret) - goto err_out; + return ERR_PTR(ret);
hr_qp = kzalloc(sizeof(*hr_qp), GFP_KERNEL); - if (!hr_qp) { - ret = -ENOMEM; - goto err_out; - } + if (!hr_qp) + return ERR_PTR(-ENOMEM);
if (init_attr->qp_type == IB_QPT_XRC_TGT) hr_qp->xrcdn = to_hr_xrcd(init_attr->xrcd)->xrcdn; @@ -1439,14 +1437,10 @@ struct ib_qp *hns_roce_create_qp(struct ib_pd *pd, init_attr->qp_type, ret);
kfree(hr_qp); - goto err_out; + return ERR_PTR(ret); }
return &hr_qp->ibqp; - -err_out: - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_QP_CREATE_ERR_CNT]); - return ERR_PTR(ret); }
int to_hr_qp_type(int qp_type) @@ -1615,8 +1609,6 @@ int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
out: mutex_unlock(&hr_qp->mutex); - if (ret) - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_QP_MODIFY_ERR_CNT]);
return ret; } diff --git a/drivers/infiniband/hw/hns/hns_roce_srq.c b/drivers/infiniband/hw/hns/hns_roce_srq.c index e135d2bbe049..24df766d549e 100644 --- a/drivers/infiniband/hw/hns/hns_roce_srq.c +++ b/drivers/infiniband/hw/hns/hns_roce_srq.c @@ -474,11 +474,11 @@ int hns_roce_create_srq(struct ib_srq *ib_srq,
ret = set_srq_param(srq, init_attr, udata); if (ret) - goto err_out; + return ret;
ret = alloc_srq_buf(hr_dev, srq, udata); if (ret) - goto err_out; + return ret;
ret = alloc_srq_db(hr_dev, srq, udata, &resp); if (ret) @@ -516,8 +516,7 @@ int hns_roce_create_srq(struct ib_srq *ib_srq, free_srq_db(hr_dev, srq, udata); err_srq_buf: free_srq_buf(hr_dev, srq); -err_out: - atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_SRQ_CREATE_ERR_CNT]); + return ret; }
From: Junxian Huang huangjunxian6@hisilicon.com
driver inclusion category: cleanup bugzilla: https://gitee.com/openeuler/kernel/issues/I8DJVZ
--------------------------------------------------------------------------
EOPNOTSUPP is more situable than EINVAL for allocating XRCD while XRC is not supported and unsupported resizing SRQ.
Fixes: 32548870d438 ("RDMA/hns: Add support for XRC on HIP09") Fixes: 221109e64316 ("RDMA/hns: Add interception for resizing SRQs") Signed-off-by: Junxian Huang huangjunxian6@hisilicon.com --- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 2 +- drivers/infiniband/hw/hns/hns_roce_pd.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 12ebe93ff9fb..88cf92863b40 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -6185,7 +6185,7 @@ static int hns_roce_v2_modify_srq(struct ib_srq *ibsrq,
/* Resizing SRQs is not supported yet */ if (srq_attr_mask & IB_SRQ_MAX_WR) - return -EINVAL; + return -EOPNOTSUPP;
if (srq_attr_mask & IB_SRQ_LIMIT) { if (srq_attr->srq_limit > srq->wqe_cnt) diff --git a/drivers/infiniband/hw/hns/hns_roce_pd.c b/drivers/infiniband/hw/hns/hns_roce_pd.c index a720801eaac9..8f3a5e976b65 100644 --- a/drivers/infiniband/hw/hns/hns_roce_pd.c +++ b/drivers/infiniband/hw/hns/hns_roce_pd.c @@ -149,7 +149,7 @@ int hns_roce_alloc_xrcd(struct ib_xrcd *ib_xrcd, struct ib_udata *udata) int ret;
if (!(hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC)) - return -EINVAL; + return -EOPNOTSUPP;
ret = hns_roce_xrcd_alloc(hr_dev, &xrcd->xrcdn); if (ret)
From: Junxian Huang huangjunxian6@hisilicon.com
driver inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8DJVZ
--------------------------------------------------------------------------
Support SW stats with debugfs.
Query output: $ cat /sys/kernel/debug/hns_roce/hns_0/sw_stat/sw_stat aeqe --- 3341 ceqe --- 0 cmds --- 6764 cmds_err --- 0 posted_mbx --- 3344 polled_mbx --- 3 mbx_event --- 3341 qp_create_err --- 0 qp_modify_err --- 0 cq_create_err --- 0 srq_create_err --- 0 xrcd_alloc_err --- 0 mr_reg_err --- 0 mr_rereg_err --- 0 ah_create_err --- 0 mmap_err --- 0 uctx_alloc_err --- 0 srq_modify_err --- 0
Signed-off-by: Junxian Huang huangjunxian6@hisilicon.com Signed-off-by: Chengchang Tang tangchengchang@huawei.com --- drivers/infiniband/hw/hns/hns_roce_ah.c | 8 +- drivers/infiniband/hw/hns/hns_roce_cmd.c | 17 ++++- drivers/infiniband/hw/hns/hns_roce_cq.c | 17 +++-- drivers/infiniband/hw/hns/hns_roce_debugfs.c | 78 ++++++++++++++++++++ drivers/infiniband/hw/hns/hns_roce_device.h | 24 ++++++ drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 42 ++++++++--- drivers/infiniband/hw/hns/hns_roce_main.c | 44 +++++++++-- drivers/infiniband/hw/hns/hns_roce_mr.c | 22 ++++-- drivers/infiniband/hw/hns/hns_roce_pd.c | 10 ++- drivers/infiniband/hw/hns/hns_roce_qp.c | 16 +++- drivers/infiniband/hw/hns/hns_roce_srq.c | 7 +- 11 files changed, 238 insertions(+), 47 deletions(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_ah.c b/drivers/infiniband/hw/hns/hns_roce_ah.c index 4404b45c5ab1..f4ceaeba5601 100644 --- a/drivers/infiniband/hw/hns/hns_roce_ah.c +++ b/drivers/infiniband/hw/hns/hns_roce_ah.c @@ -84,7 +84,7 @@ int hns_roce_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr, ret = 0;
if (ret && grh->sgid_attr->gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) - return ret; + goto err_out;
if (tc_mode == HNAE3_TC_MAP_MODE_DSCP && grh->sgid_attr->gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) @@ -100,7 +100,7 @@ int hns_roce_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr, ret = rdma_read_gid_l2_fields(ah_attr->grh.sgid_attr, &ah->av.vlan_id, NULL); if (ret) - return ret; + goto err_out;
ah->av.vlan_en = ah->av.vlan_id < VLAN_N_VID; } @@ -112,6 +112,10 @@ int hns_roce_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr, min(udata->outlen, sizeof(resp))); }
+err_out: + if (ret) + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_AH_CREATE_ERR_CNT]); + return ret; }
diff --git a/drivers/infiniband/hw/hns/hns_roce_cmd.c b/drivers/infiniband/hw/hns/hns_roce_cmd.c index 864413607571..a269578c8d89 100644 --- a/drivers/infiniband/hw/hns/hns_roce_cmd.c +++ b/drivers/infiniband/hw/hns/hns_roce_cmd.c @@ -41,7 +41,14 @@ static int hns_roce_cmd_mbox_post_hw(struct hns_roce_dev *hr_dev, struct hns_roce_mbox_msg *mbox_msg) { - return hr_dev->hw->post_mbox(hr_dev, mbox_msg); + int ret; + + ret = hr_dev->hw->post_mbox(hr_dev, mbox_msg); + if (ret) + return ret; + + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MBX_POSTED_CNT]); + return 0; }
/* this should be called with "poll_sem" */ @@ -58,7 +65,12 @@ static int __hns_roce_cmd_mbox_poll(struct hns_roce_dev *hr_dev, return ret; }
- return hr_dev->hw->poll_mbox_done(hr_dev); + ret = hr_dev->hw->poll_mbox_done(hr_dev); + if (ret) + return ret; + + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MBX_POLLED_CNT]); + return 0; }
static int hns_roce_cmd_mbox_poll(struct hns_roce_dev *hr_dev, @@ -89,6 +101,7 @@ void hns_roce_cmd_event(struct hns_roce_dev *hr_dev, u16 token, u8 status, context->result = (status == HNS_ROCE_CMD_SUCCESS) ? 0 : (-EIO); context->out_param = out_param; complete(&context->done); + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MBX_EVENT_CNT]); }
static int __hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, diff --git a/drivers/infiniband/hw/hns/hns_roce_cq.c b/drivers/infiniband/hw/hns/hns_roce_cq.c index 2d6f8c55e2b5..cd058acfa10f 100644 --- a/drivers/infiniband/hw/hns/hns_roce_cq.c +++ b/drivers/infiniband/hw/hns/hns_roce_cq.c @@ -464,34 +464,34 @@ int hns_roce_create_cq(struct ib_cq *ib_cq, const struct ib_cq_init_attr *attr, struct hns_roce_cq *hr_cq = to_hr_cq(ib_cq); struct ib_device *ibdev = &hr_dev->ib_dev; struct hns_roce_ib_create_cq ucmd = {}; - int ret; + int ret = -EOPNOTSUPP;
if (attr->flags) - return -EOPNOTSUPP; + goto err_out;
ret = verify_cq_create_attr(hr_dev, attr); if (ret) - return ret; + goto err_out;
if (udata) { ret = get_cq_ucmd(hr_cq, udata, &ucmd); if (ret) - return ret; + goto err_out;
}
ret = set_cq_param(hr_cq, attr->cqe, attr->comp_vector, &ucmd); if (ret) - return ret; + goto err_out;
ret = set_cqe_size(hr_cq, udata, &ucmd); if (ret) - return ret; + goto err_out;
ret = alloc_cq_buf(hr_dev, hr_cq, udata, ucmd.buf_addr); if (ret) { ibdev_err(ibdev, "failed to alloc CQ buf, ret = %d.\n", ret); - return ret; + goto err_out; }
ret = alloc_cq_db(hr_dev, hr_cq, udata, ucmd.db_addr, &resp); @@ -539,6 +539,9 @@ int hns_roce_create_cq(struct ib_cq *ib_cq, const struct ib_cq_init_attr *attr, free_cq_db(hr_dev, hr_cq, udata); err_cq_buf: free_cq_buf(hr_dev, hr_cq); +err_out: + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_CQ_CREATE_ERR_CNT]); + return ret; }
diff --git a/drivers/infiniband/hw/hns/hns_roce_debugfs.c b/drivers/infiniband/hw/hns/hns_roce_debugfs.c index 023b111997be..f3ce3d94cb71 100644 --- a/drivers/infiniband/hw/hns/hns_roce_debugfs.c +++ b/drivers/infiniband/hw/hns/hns_roce_debugfs.c @@ -85,11 +85,17 @@ struct hns_poe_debugfs { struct dentry *root; /* dev debugfs entry */ };
+struct hns_sw_stat_debugfs { + struct dentry *root; + struct hns_debugfs_seqfile sw_stat; +}; + /* Debugfs for device */ struct hns_roce_dev_debugfs { struct dentry *root; struct hns_dca_debugfs *dca_root; struct hns_poe_debugfs *poe_root; + struct hns_sw_stat_debugfs *sw_stat_root; };
struct dca_mem_stats { @@ -634,6 +640,71 @@ void hns_roce_unregister_uctx_debugfs(struct hns_roce_dev *hr_dev, } }
+static const char * const sw_stat_info[] = { + [HNS_ROCE_DFX_AEQE_CNT] = "aeqe", + [HNS_ROCE_DFX_CEQE_CNT] = "ceqe", + [HNS_ROCE_DFX_CMDS_CNT] = "cmds", + [HNS_ROCE_DFX_CMDS_ERR_CNT] = "cmds_err", + [HNS_ROCE_DFX_MBX_POSTED_CNT] = "posted_mbx", + [HNS_ROCE_DFX_MBX_POLLED_CNT] = "polled_mbx", + [HNS_ROCE_DFX_MBX_EVENT_CNT] = "mbx_event", + [HNS_ROCE_DFX_QP_CREATE_ERR_CNT] = "qp_create_err", + [HNS_ROCE_DFX_QP_MODIFY_ERR_CNT] = "qp_modify_err", + [HNS_ROCE_DFX_CQ_CREATE_ERR_CNT] = "cq_create_err", + [HNS_ROCE_DFX_CQ_MODIFY_ERR_CNT] = "cq_modify_err", + [HNS_ROCE_DFX_SRQ_CREATE_ERR_CNT] = "srq_create_err", + [HNS_ROCE_DFX_SRQ_MODIFY_ERR_CNT] = "srq_modify_err", + [HNS_ROCE_DFX_XRCD_ALLOC_ERR_CNT] = "xrcd_alloc_err", + [HNS_ROCE_DFX_MR_REG_ERR_CNT] = "mr_reg_err", + [HNS_ROCE_DFX_MR_REREG_ERR_CNT] = "mr_rereg_err", + [HNS_ROCE_DFX_AH_CREATE_ERR_CNT] = "ah_create_err", + [HNS_ROCE_DFX_MMAP_ERR_CNT] = "mmap_err", + [HNS_ROCE_DFX_UCTX_ALLOC_ERR_CNT] = "uctx_alloc_err", +}; + +static int sw_stat_debugfs_show(struct seq_file *file, void *offset) +{ + struct hns_roce_dev *hr_dev = file->private; + int i; + + for (i = 0; i < HNS_ROCE_DFX_CNT_TOTAL; i++) + seq_printf(file, "%-20s --- %lld\n", sw_stat_info[i], + atomic64_read(&hr_dev->dfx_cnt[i])); + + return 0; +} + +static struct hns_sw_stat_debugfs + *create_sw_stat_debugfs(struct hns_roce_dev *hr_dev, + struct dentry *parent) +{ + struct hns_sw_stat_debugfs *dbgfs; + + if (IS_ERR(parent)) + return NULL; + + dbgfs = kvzalloc(sizeof(*dbgfs), GFP_KERNEL); + if (!dbgfs) + return NULL; + + dbgfs->root = debugfs_create_dir("sw_stat", parent); + if (IS_ERR_OR_NULL(dbgfs->root)) { + kvfree(dbgfs); + return NULL; + } + + init_debugfs_seqfile(&dbgfs->sw_stat, "sw_stat", dbgfs->root, + sw_stat_debugfs_show, hr_dev); + return dbgfs; +} + +static void destroy_sw_stat_debugfs(struct hns_sw_stat_debugfs *sw_stat_dbgfs) +{ + cleanup_debugfs_seqfile(&sw_stat_dbgfs->sw_stat); + debugfs_remove_recursive(sw_stat_dbgfs->root); + kvfree(sw_stat_dbgfs); +} + /* debugfs for device */ void hns_roce_register_debugfs(struct hns_roce_dev *hr_dev) { @@ -659,6 +730,8 @@ void hns_roce_register_debugfs(struct hns_roce_dev *hr_dev) if (poe_is_supported(hr_dev)) dbgfs->poe_root = create_poe_debugfs(hr_dev, dbgfs->root);
+ dbgfs->sw_stat_root = create_sw_stat_debugfs(hr_dev, dbgfs->root); + hr_dev->dbgfs = dbgfs; }
@@ -683,6 +756,11 @@ void hns_roce_unregister_debugfs(struct hns_roce_dev *hr_dev) dbgfs->poe_root = NULL; }
+ if (dbgfs->sw_stat_root) { + destroy_sw_stat_debugfs(dbgfs->sw_stat_root); + dbgfs->sw_stat_root = NULL; + } + debugfs_remove_recursive(dbgfs->root); hr_dev->dbgfs = NULL; kfree(dbgfs); diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h index 010463d5caa2..ae9067e36bb2 100644 --- a/drivers/infiniband/hw/hns/hns_roce_device.h +++ b/drivers/infiniband/hw/hns/hns_roce_device.h @@ -994,6 +994,29 @@ enum hns_roce_hw_pkt_stat_index { HNS_ROCE_HW_CNT_TOTAL, };
+enum hns_roce_sw_dfx_stat_index { + HNS_ROCE_DFX_AEQE_CNT, + HNS_ROCE_DFX_CEQE_CNT, + HNS_ROCE_DFX_CMDS_CNT, + HNS_ROCE_DFX_CMDS_ERR_CNT, + HNS_ROCE_DFX_MBX_POSTED_CNT, + HNS_ROCE_DFX_MBX_POLLED_CNT, + HNS_ROCE_DFX_MBX_EVENT_CNT, + HNS_ROCE_DFX_QP_CREATE_ERR_CNT, + HNS_ROCE_DFX_QP_MODIFY_ERR_CNT, + HNS_ROCE_DFX_CQ_CREATE_ERR_CNT, + HNS_ROCE_DFX_CQ_MODIFY_ERR_CNT, + HNS_ROCE_DFX_SRQ_CREATE_ERR_CNT, + HNS_ROCE_DFX_SRQ_MODIFY_ERR_CNT, + HNS_ROCE_DFX_XRCD_ALLOC_ERR_CNT, + HNS_ROCE_DFX_MR_REG_ERR_CNT, + HNS_ROCE_DFX_MR_REREG_ERR_CNT, + HNS_ROCE_DFX_AH_CREATE_ERR_CNT, + HNS_ROCE_DFX_MMAP_ERR_CNT, + HNS_ROCE_DFX_UCTX_ALLOC_ERR_CNT, + HNS_ROCE_DFX_CNT_TOTAL +}; + struct hns_roce_hw { int (*cmq_init)(struct hns_roce_dev *hr_dev); void (*cmq_exit)(struct hns_roce_dev *hr_dev); @@ -1153,6 +1176,7 @@ struct hns_roce_dev {
struct notifier_block bond_nb; struct hns_roce_port port_data[HNS_ROCE_MAX_PORTS]; + atomic64_t *dfx_cnt; struct hns_roce_poe_ctx poe_ctx; /* poe ch array */
struct rdma_notify_mem *notify_tbl; diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 88cf92863b40..9064729b5d91 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -1416,6 +1416,8 @@ static int __hns_roce_cmq_send(struct hns_roce_dev *hr_dev, /* Write to hardware */ roce_write(hr_dev, ROCEE_TX_CMQ_PI_REG, csq->head);
+ atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_CMDS_CNT]); + do { if (hns_roce_cmq_csq_done(hr_dev)) break; @@ -1455,6 +1457,9 @@ static int __hns_roce_cmq_send(struct hns_roce_dev *hr_dev,
spin_unlock_bh(&csq->lock);
+ if (ret) + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_CMDS_ERR_CNT]); + return ret; }
@@ -6181,19 +6186,23 @@ static int hns_roce_v2_modify_srq(struct ib_srq *ibsrq, struct hns_roce_srq_context *srq_context; struct hns_roce_srq_context *srqc_mask; struct hns_roce_cmd_mailbox *mailbox; - int ret; + int ret = -EOPNOTSUPP;
/* Resizing SRQs is not supported yet */ if (srq_attr_mask & IB_SRQ_MAX_WR) - return -EOPNOTSUPP; + goto out;
if (srq_attr_mask & IB_SRQ_LIMIT) { - if (srq_attr->srq_limit > srq->wqe_cnt) - return -EINVAL; + if (srq_attr->srq_limit > srq->wqe_cnt) { + ret = -EINVAL; + goto out; + }
mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); - if (IS_ERR(mailbox)) - return PTR_ERR(mailbox); + if (IS_ERR(mailbox)) { + ret = PTR_ERR(mailbox); + goto out; + }
srq_context = mailbox->buf; srqc_mask = (struct hns_roce_srq_context *)mailbox->buf + 1; @@ -6206,15 +6215,17 @@ static int hns_roce_v2_modify_srq(struct ib_srq *ibsrq, ret = hns_roce_cmd_mbox(hr_dev, mailbox->dma, 0, HNS_ROCE_CMD_MODIFY_SRQC, srq->srqn); hns_roce_free_cmd_mailbox(hr_dev, mailbox); - if (ret) { + if (ret) ibdev_err(&hr_dev->ib_dev, "failed to handle cmd of modifying SRQ, ret = %d.\n", ret); - return ret; - } }
- return 0; +out: + if (ret) + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_SRQ_MODIFY_ERR_CNT]); + + return ret; }
static int hns_roce_v2_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr) @@ -6258,8 +6269,9 @@ static int hns_roce_v2_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period) int ret;
mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); - if (IS_ERR(mailbox)) - return PTR_ERR(mailbox); + ret = PTR_ERR_OR_ZERO(mailbox); + if (ret) + goto err_out;
cq_context = mailbox->buf; cqc_mask = (struct hns_roce_v2_cq_context *)mailbox->buf + 1; @@ -6289,6 +6301,10 @@ static int hns_roce_v2_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period) "failed to process cmd when modifying CQ, ret = %d.\n", ret);
+err_out: + if (ret) + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_CQ_MODIFY_ERR_CNT]); + return ret; }
@@ -6527,6 +6543,7 @@ static irqreturn_t hns_roce_v2_aeq_int(struct hns_roce_dev *hr_dev, eq->sub_type = sub_type; ++eq->cons_index; aeqe_found = IRQ_HANDLED; + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_AEQE_CNT]);
hns_roce_v2_init_irq_work(hr_dev, eq, queue_num);
@@ -6569,6 +6586,7 @@ static irqreturn_t hns_roce_v2_ceq_int(struct hns_roce_dev *hr_dev,
++eq->cons_index; ceqe_found = IRQ_HANDLED; + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_CEQE_CNT]);
ceqe = next_ceqe_sw_v2(eq); } diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c index f9e304296cf0..88db61fc3b9d 100644 --- a/drivers/infiniband/hw/hns/hns_roce_main.c +++ b/drivers/infiniband/hw/hns/hns_roce_main.c @@ -569,10 +569,10 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx, struct hns_roce_dev *hr_dev = to_hr_dev(uctx->device); struct hns_roce_ib_alloc_ucontext_resp resp = {}; struct hns_roce_ib_alloc_ucontext ucmd = {}; - int ret; + int ret = -EAGAIN;
if (!hr_dev->active) - return -EAGAIN; + goto error_fail_uar_alloc;
context->pid = current->pid; INIT_LIST_HEAD(&context->list); @@ -580,7 +580,7 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx, ret = ib_copy_from_udata(&ucmd, udata, min(udata->inlen, sizeof(ucmd))); if (ret) - return ret; + goto error_fail_uar_alloc;
hns_roce_get_uctx_config(hr_dev, context, &ucmd, &resp);
@@ -629,6 +629,8 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx, ida_free(&hr_dev->uar_ida.ida, (int)context->uar.logic_idx);
error_fail_uar_alloc: + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_UCTX_ALLOC_ERR_CNT]); + return ret; }
@@ -691,8 +693,10 @@ static int hns_roce_mmap(struct ib_ucontext *uctx, struct vm_area_struct *vma) int ret;
rdma_entry = rdma_user_mmap_entry_get_pgoff(uctx, vma->vm_pgoff); - if (!rdma_entry) + if (!rdma_entry) { + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MMAP_ERR_CNT]); return -EINVAL; + }
entry = to_hns_mmap(rdma_entry); pfn = entry->address >> PAGE_SHIFT; @@ -724,6 +728,8 @@ static int hns_roce_mmap(struct ib_ucontext *uctx, struct vm_area_struct *vma)
out: rdma_user_mmap_entry_put(rdma_entry); + if (ret) + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MMAP_ERR_CNT]);
return ret; } @@ -812,13 +818,12 @@ static struct rdma_hw_stats *hns_roce_alloc_hw_port_stats(struct ib_device *devi u8 port_num) { struct hns_roce_dev *hr_dev = to_hr_dev(device); - u32 port = port_num - 1;
if (hr_dev->pci_dev->revision <= PCI_REVISION_ID_HIP08 || hr_dev->is_vf) return NULL;
- if (port > hr_dev->caps.num_ports) { + if (port_num > hr_dev->caps.num_ports) { ibdev_err(device, "invalid port num.\n"); return NULL; } @@ -1423,6 +1428,21 @@ static void hns_roce_unregister_poe_ch(struct hns_roce_dev *hr_dev) kvfree(hr_dev->poe_ctx.poe_ch); }
+static int hns_roce_alloc_dfx_cnt(struct hns_roce_dev *hr_dev) +{ + hr_dev->dfx_cnt = kvcalloc(HNS_ROCE_DFX_CNT_TOTAL, sizeof(atomic64_t), + GFP_KERNEL); + if (!hr_dev->dfx_cnt) + return -ENOMEM; + + return 0; +} + +static void hns_roce_dealloc_dfx_cnt(struct hns_roce_dev *hr_dev) +{ + kvfree(hr_dev->dfx_cnt); +} + int hns_roce_init(struct hns_roce_dev *hr_dev) { struct device *dev = hr_dev->dev; @@ -1430,11 +1450,17 @@ int hns_roce_init(struct hns_roce_dev *hr_dev)
hr_dev->is_reset = false;
+ ret = hns_roce_alloc_dfx_cnt(hr_dev); + if (ret) { + dev_err(dev, "Alloc dfx_cnt failed!\n"); + return ret; + } + if (hr_dev->hw->cmq_init) { ret = hr_dev->hw->cmq_init(hr_dev); if (ret) { dev_err(dev, "Init RoCE Command Queue failed!\n"); - return ret; + goto error_failed_alloc_dfx_cnt; } }
@@ -1515,6 +1541,9 @@ int hns_roce_init(struct hns_roce_dev *hr_dev) if (hr_dev->hw->cmq_exit) hr_dev->hw->cmq_exit(hr_dev);
+error_failed_alloc_dfx_cnt: + hns_roce_dealloc_dfx_cnt(hr_dev); + return ret; }
@@ -1537,6 +1566,7 @@ void hns_roce_exit(struct hns_roce_dev *hr_dev, bool bond_cleanup) hns_roce_cmd_cleanup(hr_dev); if (hr_dev->hw->cmq_exit) hr_dev->hw->cmq_exit(hr_dev); + hns_roce_dealloc_dfx_cnt(hr_dev); if (hr_dev->notify_tbl) kvfree(hr_dev->notify_tbl); } diff --git a/drivers/infiniband/hw/hns/hns_roce_mr.c b/drivers/infiniband/hw/hns/hns_roce_mr.c index a2f07a5f9501..0b5108d79219 100644 --- a/drivers/infiniband/hw/hns/hns_roce_mr.c +++ b/drivers/infiniband/hw/hns/hns_roce_mr.c @@ -235,8 +235,10 @@ struct ib_mr *hns_roce_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, int ret;
mr = kzalloc(sizeof(*mr), GFP_KERNEL); - if (!mr) - return ERR_PTR(-ENOMEM); + if (!mr) { + ret = -ENOMEM; + goto err_out; + }
mr->iova = virt_addr; mr->size = length; @@ -266,6 +268,9 @@ struct ib_mr *hns_roce_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, free_mr_key(hr_dev, mr); err_alloc_mr: kfree(mr); +err_out: + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MR_REG_ERR_CNT]); + return ERR_PTR(ret); }
@@ -280,12 +285,15 @@ int hns_roce_rereg_user_mr(struct ib_mr *ibmr, int flags, u64 start, u64 length, unsigned long mtpt_idx; int ret;
- if (!mr->enabled) - return -EINVAL; + if (!mr->enabled) { + ret = -EINVAL; + goto err_out; + }
mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); - if (IS_ERR(mailbox)) - return PTR_ERR(mailbox); + ret = PTR_ERR_OR_ZERO(mailbox); + if (ret) + goto err_out;
mtpt_idx = key_to_hw_index(mr->key) & (hr_dev->caps.num_mtpts - 1); ret = hns_roce_cmd_mbox(hr_dev, 0, mailbox->dma, HNS_ROCE_CMD_QUERY_MPT, @@ -335,6 +343,8 @@ int hns_roce_rereg_user_mr(struct ib_mr *ibmr, int flags, u64 start, u64 length,
free_cmd_mbox: hns_roce_free_cmd_mailbox(hr_dev, mailbox); +err_out: + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MR_REREG_ERR_CNT]);
return ret; } diff --git a/drivers/infiniband/hw/hns/hns_roce_pd.c b/drivers/infiniband/hw/hns/hns_roce_pd.c index 8f3a5e976b65..4b95f16afeca 100644 --- a/drivers/infiniband/hw/hns/hns_roce_pd.c +++ b/drivers/infiniband/hw/hns/hns_roce_pd.c @@ -146,16 +146,18 @@ int hns_roce_alloc_xrcd(struct ib_xrcd *ib_xrcd, struct ib_udata *udata) { struct hns_roce_dev *hr_dev = to_hr_dev(ib_xrcd->device); struct hns_roce_xrcd *xrcd = to_hr_xrcd(ib_xrcd); - int ret; + int ret = -EOPNOTSUPP;
if (!(hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC)) - return -EOPNOTSUPP; + goto err_out;
ret = hns_roce_xrcd_alloc(hr_dev, &xrcd->xrcdn); + +err_out: if (ret) - return ret; + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_XRCD_ALLOC_ERR_CNT]);
- return 0; + return ret; }
int hns_roce_dealloc_xrcd(struct ib_xrcd *ib_xrcd, struct ib_udata *udata) diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c index b1a102970d71..e8e5641ec692 100644 --- a/drivers/infiniband/hw/hns/hns_roce_qp.c +++ b/drivers/infiniband/hw/hns/hns_roce_qp.c @@ -1417,11 +1417,13 @@ struct ib_qp *hns_roce_create_qp(struct ib_pd *pd,
ret = check_qp_type(hr_dev, init_attr->qp_type, !!udata); if (ret) - return ERR_PTR(ret); + goto err_out;
hr_qp = kzalloc(sizeof(*hr_qp), GFP_KERNEL); - if (!hr_qp) - return ERR_PTR(-ENOMEM); + if (!hr_qp) { + ret = -ENOMEM; + goto err_out; + }
if (init_attr->qp_type == IB_QPT_XRC_TGT) hr_qp->xrcdn = to_hr_xrcd(init_attr->xrcd)->xrcdn; @@ -1437,10 +1439,14 @@ struct ib_qp *hns_roce_create_qp(struct ib_pd *pd, init_attr->qp_type, ret);
kfree(hr_qp); - return ERR_PTR(ret); + goto err_out; }
return &hr_qp->ibqp; + +err_out: + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_QP_CREATE_ERR_CNT]); + return ERR_PTR(ret); }
int to_hr_qp_type(int qp_type) @@ -1609,6 +1615,8 @@ int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
out: mutex_unlock(&hr_qp->mutex); + if (ret) + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_QP_MODIFY_ERR_CNT]);
return ret; } diff --git a/drivers/infiniband/hw/hns/hns_roce_srq.c b/drivers/infiniband/hw/hns/hns_roce_srq.c index 24df766d549e..e135d2bbe049 100644 --- a/drivers/infiniband/hw/hns/hns_roce_srq.c +++ b/drivers/infiniband/hw/hns/hns_roce_srq.c @@ -474,11 +474,11 @@ int hns_roce_create_srq(struct ib_srq *ib_srq,
ret = set_srq_param(srq, init_attr, udata); if (ret) - return ret; + goto err_out;
ret = alloc_srq_buf(hr_dev, srq, udata); if (ret) - return ret; + goto err_out;
ret = alloc_srq_db(hr_dev, srq, udata, &resp); if (ret) @@ -516,7 +516,8 @@ int hns_roce_create_srq(struct ib_srq *ib_srq, free_srq_db(hr_dev, srq, udata); err_srq_buf: free_srq_buf(hr_dev, srq); - +err_out: + atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_SRQ_CREATE_ERR_CNT]); return ret; }
From: Junxian Huang huangjunxian6@hisilicon.com
driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8DJVZ
--------------------------------------------------------------------------
It's suggested that the errors returned by debugfs functions should be ignored, as these functions can handle an error dentry. So remove all the return value checks.
Fixes: 9bde3d2b912f ("RDMA/hns: Support SW stats with debugfs") Fixes: a21781182f77 ("RDMA/hns: Add debugfs support for DCA") Signed-off-by: Junxian Huang huangjunxian6@hisilicon.com --- drivers/infiniband/hw/hns/hns_roce_debugfs.c | 31 -------------------- 1 file changed, 31 deletions(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_debugfs.c b/drivers/infiniband/hw/hns/hns_roce_debugfs.c index f3ce3d94cb71..d39e666d9a97 100644 --- a/drivers/infiniband/hw/hns/hns_roce_debugfs.c +++ b/drivers/infiniband/hw/hns/hns_roce_debugfs.c @@ -46,8 +46,6 @@ static void init_debugfs_seqfile(struct hns_debugfs_seqfile *seq,
entry = debugfs_create_file(name, 0400, parent, seq, &hns_debugfs_seqfile_fops); - if (IS_ERR(entry)) - return;
seq->read = read_fn; seq->data = data; @@ -450,13 +448,8 @@ static void init_dca_ctx_debugfs(struct hns_dca_ctx_debugfs *dbgfs, { char name[DCA_CTX_PID_LEN];
- if (IS_ERR_OR_NULL(parent)) - return; - dca_setup_pool_name(uctx ? uctx->pid : 0, !uctx, name, sizeof(name)); dbgfs->root = debugfs_create_dir(name, parent); - if (IS_ERR_OR_NULL(dbgfs->root)) - return;
if (uctx) { init_debugfs_seqfile(&dbgfs->mem, "mstats", dbgfs->root, @@ -483,18 +476,11 @@ create_dca_debugfs(struct hns_roce_dev *hr_dev, struct dentry *parent) { struct hns_dca_debugfs *dbgfs;
- if (IS_ERR(parent)) - return NULL; - dbgfs = kzalloc(sizeof(*dbgfs), GFP_KERNEL); if (!dbgfs) return NULL;
dbgfs->root = debugfs_create_dir("dca", parent); - if (IS_ERR_OR_NULL(dbgfs->root)) { - kfree(dbgfs); - return NULL; - }
init_debugfs_seqfile(&dbgfs->pool, "pool", dbgfs->root, dca_debugfs_pool_show, hr_dev); @@ -680,18 +666,11 @@ static struct hns_sw_stat_debugfs { struct hns_sw_stat_debugfs *dbgfs;
- if (IS_ERR(parent)) - return NULL; - dbgfs = kvzalloc(sizeof(*dbgfs), GFP_KERNEL); if (!dbgfs) return NULL;
dbgfs->root = debugfs_create_dir("sw_stat", parent); - if (IS_ERR_OR_NULL(dbgfs->root)) { - kvfree(dbgfs); - return NULL; - }
init_debugfs_seqfile(&dbgfs->sw_stat, "sw_stat", dbgfs->root, sw_stat_debugfs_show, hr_dev); @@ -710,19 +689,12 @@ void hns_roce_register_debugfs(struct hns_roce_dev *hr_dev) { struct hns_roce_dev_debugfs *dbgfs;
- if (IS_ERR_OR_NULL(hns_roce_dbgfs_root)) - return; - dbgfs = kzalloc(sizeof(*dbgfs), GFP_KERNEL); if (!dbgfs) return;
dbgfs->root = debugfs_create_dir(dev_name(&hr_dev->ib_dev.dev), hns_roce_dbgfs_root); - if (IS_ERR(dbgfs->root)) { - kfree(dbgfs); - return; - }
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_DCA_MODE) dbgfs->dca_root = create_dca_debugfs(hr_dev, dbgfs->root); @@ -739,9 +711,6 @@ void hns_roce_unregister_debugfs(struct hns_roce_dev *hr_dev) { struct hns_roce_dev_debugfs *dbgfs;
- if (IS_ERR_OR_NULL(hns_roce_dbgfs_root)) - return; - dbgfs = hr_dev->dbgfs; if (!dbgfs) return;
From: Junxian Huang huangjunxian6@hisilicon.com
driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8DJVZ
--------------------------------------------------------------------------
As HW stats are not supported for VF and HIP08, just don't set the HW stats ops to ib-core in these cases.
Fixes: 8681236b9ca9 ("Revert "RDMA/hns: Add dfx cnt stats"") Fixes: 05491dda8e9b ("RDMA/hns: Support hns HW stats") Signed-off-by: Junxian Huang huangjunxian6@hisilicon.com --- drivers/infiniband/hw/hns/hns_roce_main.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c index 88db61fc3b9d..8641cb38cd07 100644 --- a/drivers/infiniband/hw/hns/hns_roce_main.c +++ b/drivers/infiniband/hw/hns/hns_roce_main.c @@ -819,10 +819,6 @@ static struct rdma_hw_stats *hns_roce_alloc_hw_port_stats(struct ib_device *devi { struct hns_roce_dev *hr_dev = to_hr_dev(device);
- if (hr_dev->pci_dev->revision <= PCI_REVISION_ID_HIP08 || - hr_dev->is_vf) - return NULL; - if (port_num > hr_dev->caps.num_ports) { ibdev_err(device, "invalid port num.\n"); return NULL; @@ -847,10 +843,6 @@ static int hns_roce_get_hw_stats(struct ib_device *device, if (port > hr_dev->caps.num_ports) return -EINVAL;
- if (hr_dev->pci_dev->revision <= PCI_REVISION_ID_HIP08 || - hr_dev->is_vf) - return -EOPNOTSUPP; - ret = hr_dev->hw->query_hw_counter(hr_dev, stats->value, port, &num_counters); if (ret) { @@ -941,8 +933,6 @@ static const struct ib_device_ops hns_roce_dev_ops = { .query_pkey = hns_roce_query_pkey, .query_port = hns_roce_query_port, .reg_user_mr = hns_roce_reg_user_mr, - .alloc_hw_stats = hns_roce_alloc_hw_port_stats, - .get_hw_stats = hns_roce_get_hw_stats, .init_port = hns_roce_create_port_files,
INIT_RDMA_OBJ_SIZE(ib_ah, hns_roce_ah, ibah), @@ -951,6 +941,11 @@ static const struct ib_device_ops hns_roce_dev_ops = { INIT_RDMA_OBJ_SIZE(ib_ucontext, hns_roce_ucontext, ibucontext), };
+static const struct ib_device_ops hns_roce_dev_hw_stats_ops = { + .alloc_hw_stats = hns_roce_alloc_hw_port_stats, + .get_hw_stats = hns_roce_get_hw_stats, +}; + static const struct ib_device_ops hns_roce_dev_mr_ops = { .rereg_user_mr = hns_roce_rereg_user_mr, }; @@ -1073,6 +1068,10 @@ static int hns_roce_register_device(struct hns_roce_dev *hr_dev) ib_set_device_ops(ib_dev, &hns_roce_dev_xrcd_ops); }
+ if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09 && + !hr_dev->is_vf) + ib_set_device_ops(ib_dev, &hns_roce_dev_hw_stats_ops); + ib_set_device_ops(ib_dev, hr_dev->hw->hns_roce_dev_ops); ib_set_device_ops(ib_dev, &hns_roce_dev_ops); ib_set_device_ops(ib_dev, &hns_roce_dev_restrack_ops);