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>
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
)))
21 if (rdma_nl_put_driver_u32(msg
, "ceqn",
22 roce_get_field(context
->byte_4_pg_ceqn
,
24 V2_CQC_BYTE_4_CEQN_S
)))
27 if (rdma_nl_put_driver_u32(msg
, "cqn",
28 roce_get_field(context
->byte_8_cqn
,
30 V2_CQC_BYTE_8_CQN_S
)))
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
)))
39 if (rdma_nl_put_driver_u32(
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
)))
46 if (rdma_nl_put_driver_u32(
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
)))
53 if (rdma_nl_put_driver_u32(
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
)))
60 if (rdma_nl_put_driver_u32(
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
)))
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
)))
79 int hns_roce_fill_res_cq_entry(struct sk_buff
*msg
,
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
;
88 if (!hr_dev
->dfx
->query_cqc_info
)
91 context
= kzalloc(sizeof(struct hns_roce_v2_cq_context
), GFP_KERNEL
);
95 ret
= hr_dev
->dfx
->query_cqc_info(hr_dev
, hr_cq
->cqn
, (int *)context
);
99 table_attr
= nla_nest_start(msg
, RDMA_NLDEV_ATTR_DRIVER
);
105 if (hns_roce_fill_cq(msg
, context
)) {
107 goto err_cancel_table
;
110 nla_nest_end(msg
, table_attr
);
116 nla_nest_cancel(msg
, table_attr
);