WIP FPC-III support
[linux/fpc-iii.git] / drivers / infiniband / hw / hns / hns_roce_restrack.c
blob259444c0a6301a547e76843bb9a488fa14b5fff8
1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2 // Copyright (c) 2019 Hisilicon Limited.
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"
12 static int hns_roce_fill_cq(struct sk_buff *msg,
13 struct hns_roce_v2_cq_context *context)
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;
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;
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;
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;
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;
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;
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;
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;
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;
73 return 0;
75 err:
76 return -EMSGSIZE;
79 int hns_roce_fill_res_cq_entry(struct sk_buff *msg,
80 struct ib_cq *ib_cq)
82 struct hns_roce_dev *hr_dev = to_hr_dev(ib_cq->device);
83 struct hns_roce_cq *hr_cq = to_hr_cq(ib_cq);
84 struct hns_roce_v2_cq_context *context;
85 struct nlattr *table_attr;
86 int ret;
88 if (!hr_dev->dfx->query_cqc_info)
89 return -EINVAL;
91 context = kzalloc(sizeof(struct hns_roce_v2_cq_context), GFP_KERNEL);
92 if (!context)
93 return -ENOMEM;
95 ret = hr_dev->dfx->query_cqc_info(hr_dev, hr_cq->cqn, (int *)context);
96 if (ret)
97 goto err;
99 table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER);
100 if (!table_attr) {
101 ret = -EMSGSIZE;
102 goto err;
105 if (hns_roce_fill_cq(msg, context)) {
106 ret = -EMSGSIZE;
107 goto err_cancel_table;
110 nla_nest_end(msg, table_attr);
111 kfree(context);
113 return 0;
115 err_cancel_table:
116 nla_nest_cancel(msg, table_attr);
117 err:
118 kfree(context);
119 return ret;