This source file includes following definitions.
- hns_roce_fill_cq
- hns_roce_fill_res_cq_entry
- hns_roce_fill_res_entry
1
2
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
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 roce_get_field(context->byte_4_pg_ceqn,
17 V2_CQC_BYTE_4_ARM_ST_M,
18 V2_CQC_BYTE_4_ARM_ST_S)))
19 goto err;
20
21 if (rdma_nl_put_driver_u32(msg, "ceqn",
22 roce_get_field(context->byte_4_pg_ceqn,
23 V2_CQC_BYTE_4_CEQN_M,
24 V2_CQC_BYTE_4_CEQN_S)))
25 goto err;
26
27 if (rdma_nl_put_driver_u32(msg, "cqn",
28 roce_get_field(context->byte_8_cqn,
29 V2_CQC_BYTE_8_CQN_M,
30 V2_CQC_BYTE_8_CQN_S)))
31 goto err;
32
33 if (rdma_nl_put_driver_u32(msg, "hopnum",
34 roce_get_field(context->byte_16_hop_addr,
35 V2_CQC_BYTE_16_CQE_HOP_NUM_M,
36 V2_CQC_BYTE_16_CQE_HOP_NUM_S)))
37 goto err;
38
39 if (rdma_nl_put_driver_u32(
40 msg, "pi",
41 roce_get_field(context->byte_28_cq_pi,
42 V2_CQC_BYTE_28_CQ_PRODUCER_IDX_M,
43 V2_CQC_BYTE_28_CQ_PRODUCER_IDX_S)))
44 goto err;
45
46 if (rdma_nl_put_driver_u32(
47 msg, "ci",
48 roce_get_field(context->byte_32_cq_ci,
49 V2_CQC_BYTE_32_CQ_CONSUMER_IDX_M,
50 V2_CQC_BYTE_32_CQ_CONSUMER_IDX_S)))
51 goto err;
52
53 if (rdma_nl_put_driver_u32(
54 msg, "coalesce",
55 roce_get_field(context->byte_56_cqe_period_maxcnt,
56 V2_CQC_BYTE_56_CQ_MAX_CNT_M,
57 V2_CQC_BYTE_56_CQ_MAX_CNT_S)))
58 goto err;
59
60 if (rdma_nl_put_driver_u32(
61 msg, "period",
62 roce_get_field(context->byte_56_cqe_period_maxcnt,
63 V2_CQC_BYTE_56_CQ_PERIOD_M,
64 V2_CQC_BYTE_56_CQ_PERIOD_S)))
65 goto err;
66
67 if (rdma_nl_put_driver_u32(msg, "cnt",
68 roce_get_field(context->byte_52_cqe_cnt,
69 V2_CQC_BYTE_52_CQE_CNT_M,
70 V2_CQC_BYTE_52_CQE_CNT_S)))
71 goto err;
72
73 return 0;
74
75 err:
76 return -EMSGSIZE;
77 }
78
79 static int hns_roce_fill_res_cq_entry(struct sk_buff *msg,
80 struct rdma_restrack_entry *res)
81 {
82 struct ib_cq *ib_cq = container_of(res, struct ib_cq, res);
83 struct hns_roce_dev *hr_dev = to_hr_dev(ib_cq->device);
84 struct hns_roce_cq *hr_cq = to_hr_cq(ib_cq);
85 struct hns_roce_v2_cq_context *context;
86 struct nlattr *table_attr;
87 int ret;
88
89 if (!hr_dev->dfx->query_cqc_info)
90 return -EINVAL;
91
92 context = kzalloc(sizeof(struct hns_roce_v2_cq_context), GFP_KERNEL);
93 if (!context)
94 return -ENOMEM;
95
96 ret = hr_dev->dfx->query_cqc_info(hr_dev, hr_cq->cqn, (int *)context);
97 if (ret)
98 return -EINVAL;
99
100 table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER);
101 if (!table_attr) {
102 ret = -EMSGSIZE;
103 goto err;
104 }
105
106 if (hns_roce_fill_cq(msg, context)) {
107 ret = -EMSGSIZE;
108 goto err_cancel_table;
109 }
110
111 nla_nest_end(msg, table_attr);
112 kfree(context);
113
114 return 0;
115
116 err_cancel_table:
117 nla_nest_cancel(msg, table_attr);
118 err:
119 kfree(context);
120 return ret;
121 }
122
123 int hns_roce_fill_res_entry(struct sk_buff *msg,
124 struct rdma_restrack_entry *res)
125 {
126 if (res->type == RDMA_RESTRACK_CQ)
127 return hns_roce_fill_res_cq_entry(msg, res);
128
129 return 0;
130 }