1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2 // Copyright (c) 2019 Hisilicon Limited.
3
4 #include <rdma/rdma_cm.h>
5 #include <rdma/restrack.h>
6 #include <uapi/rdma/rdma_netlink.h>
7 #include "hnae3.h"
8 #include "hns_roce_common.h"
9 #include "hns_roce_device.h"
10 #include "hns_roce_hw_v2.h"
11
hns_roce_fill_cq(struct sk_buff * msg,struct hns_roce_v2_cq_context * context)12 static int hns_roce_fill_cq(struct sk_buff *msg,
13 struct hns_roce_v2_cq_context *context)
14 {
15 if (rdma_nl_put_driver_u32(msg, "state",
16 hr_reg_read(context, CQC_ARM_ST)))
17
18 goto err;
19
20 if (rdma_nl_put_driver_u32(msg, "ceqn",
21 hr_reg_read(context, CQC_CEQN)))
22 goto err;
23
24 if (rdma_nl_put_driver_u32(msg, "cqn",
25 hr_reg_read(context, CQC_CQN)))
26 goto err;
27
28 if (rdma_nl_put_driver_u32(msg, "hopnum",
29 hr_reg_read(context, CQC_CQE_HOP_NUM)))
30 goto err;
31
32 if (rdma_nl_put_driver_u32(msg, "pi",
33 hr_reg_read(context, CQC_CQ_PRODUCER_IDX)))
34 goto err;
35
36 if (rdma_nl_put_driver_u32(msg, "ci",
37 hr_reg_read(context, CQC_CQ_CONSUMER_IDX)))
38 goto err;
39
40 if (rdma_nl_put_driver_u32(msg, "coalesce",
41 hr_reg_read(context, CQC_CQ_MAX_CNT)))
42 goto err;
43
44 if (rdma_nl_put_driver_u32(msg, "period",
45 hr_reg_read(context, CQC_CQ_PERIOD)))
46 goto err;
47
48 if (rdma_nl_put_driver_u32(msg, "cnt",
49 hr_reg_read(context, CQC_CQE_CNT)))
50 goto err;
51
52 return 0;
53
54 err:
55 return -EMSGSIZE;
56 }
57
hns_roce_fill_res_cq_entry(struct sk_buff * msg,struct ib_cq * ib_cq)58 int hns_roce_fill_res_cq_entry(struct sk_buff *msg,
59 struct ib_cq *ib_cq)
60 {
61 struct hns_roce_dev *hr_dev = to_hr_dev(ib_cq->device);
62 struct hns_roce_cq *hr_cq = to_hr_cq(ib_cq);
63 struct hns_roce_v2_cq_context *context;
64 struct nlattr *table_attr;
65 int ret;
66
67 if (!hr_dev->dfx->query_cqc_info)
68 return -EINVAL;
69
70 context = kzalloc(sizeof(struct hns_roce_v2_cq_context), GFP_KERNEL);
71 if (!context)
72 return -ENOMEM;
73
74 ret = hr_dev->dfx->query_cqc_info(hr_dev, hr_cq->cqn, (int *)context);
75 if (ret)
76 goto err;
77
78 table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER);
79 if (!table_attr) {
80 ret = -EMSGSIZE;
81 goto err;
82 }
83
84 if (hns_roce_fill_cq(msg, context)) {
85 ret = -EMSGSIZE;
86 goto err_cancel_table;
87 }
88
89 nla_nest_end(msg, table_attr);
90 kfree(context);
91
92 return 0;
93
94 err_cancel_table:
95 nla_nest_cancel(msg, table_attr);
96 err:
97 kfree(context);
98 return ret;
99 }
100