Line data Source code
1 : /**
2 : * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #define _GNU_SOURCE
12 : #include "ra_adp.h"
13 : #include "rs.h"
14 : #include "ra_adp_verbs.h"
15 :
16 : static struct RaRsVerbsOps gRaRsVerbsOps = {
17 : .qpCreateWithCQWithAttrs = RsQpCreateWithCQWithAttrs,
18 : .typicalCqCreate = RsTypicalCqCreate,
19 : .typicalCqDestroy = RsTypicalCqDestroy,
20 : .getLiteCqAttr = RsGetLiteCqAttr,
21 : .qpDestroyWithoutCQ = RsQpDestroyWithoutCQ,
22 : .getLiteQpAttr = RsGetLiteQpAttr,
23 : };
24 :
25 0 : int RaRsQpCreateWithCQWithAttrs(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
26 : {
27 : (void)outLen;
28 0 : union OpQpCreateWithCQWithAttrsData *createData = NULL;
29 0 : struct RsQpNormWithAttrs qpNorm = {0};
30 0 : struct RsQpRespWithAttrs qpResp = {0};
31 :
32 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpCreateWithCQWithAttrsData), sizeof(struct MsgHead), rcvBufLen,
33 : opResult);
34 :
35 0 : createData = (union OpQpCreateWithCQWithAttrsData *)(inBuf + sizeof(struct MsgHead));
36 :
37 0 : qpNorm.isExp = 1;
38 0 : qpNorm.isExt = 1;
39 0 : qpNorm.extAttrs = createData->txData.extAttrs;
40 :
41 0 : *opResult = gRaRsVerbsOps.qpCreateWithCQWithAttrs(createData->txData.phyId, createData->txData.rdevIndex,
42 : createData->txData.sendCqn, createData->txData.recvCqn, &qpNorm, &qpResp);
43 0 : if (*opResult != 0) {
44 0 : hccp_err("qp create with cq with attrs failed ret[%d].", *opResult);
45 0 : return 0;
46 : }
47 :
48 0 : createData = (union OpQpCreateWithCQWithAttrsData *)(outBuf + sizeof(struct MsgHead));
49 0 : createData->rxData.qpn = qpResp.qpn;
50 0 : createData->rxData.psn = qpResp.psn;
51 0 : createData->rxData.gidIdx = qpResp.gidIdx;
52 :
53 0 : return 0;
54 : }
55 :
56 0 : int RaRsTypicalCqCreate(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
57 : {
58 : (void)outLen;
59 0 : union OpTypicalCqCreateData *createData = (union OpTypicalCqCreateData *)(inBuf + sizeof(struct MsgHead));
60 0 : unsigned int cqn = 0;
61 :
62 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTypicalCqCreateData), sizeof(struct MsgHead), rcvBufLen, opResult);
63 :
64 0 : *opResult = gRaRsVerbsOps.typicalCqCreate(createData->txData.phyId, createData->txData.rdevIndex,
65 : createData->txData.cqDepth, &cqn);
66 0 : if (*opResult != 0) {
67 0 : hccp_err("typical cq create failed ret[%d].", *opResult);
68 0 : return 0;
69 : }
70 :
71 0 : createData = (union OpTypicalCqCreateData *)(outBuf + sizeof(struct MsgHead));
72 0 : createData->rxData.cqn = cqn;
73 :
74 0 : return 0;
75 : }
76 :
77 0 : int RaRsTypicalCqDestroy(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
78 : {
79 : (void)outBuf;
80 : (void)outLen;
81 0 : union OpTypicalCqDestroyData *destroyData = (union OpTypicalCqDestroyData *)(inBuf + sizeof(struct MsgHead));
82 :
83 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTypicalCqDestroyData), sizeof(struct MsgHead), rcvBufLen, opResult);
84 :
85 0 : *opResult = gRaRsVerbsOps.typicalCqDestroy(destroyData->txData.phyId, destroyData->txData.rdevIndex,
86 : destroyData->txData.cqn);
87 0 : if (*opResult != 0) {
88 0 : hccp_err("typical cq destroy failed ret[%d].", *opResult);
89 0 : return 0;
90 : }
91 :
92 0 : return 0;
93 : }
94 :
95 0 : int RaRsGetLiteCqAttr(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
96 : {
97 : (void)outLen;
98 0 : union OpGetLiteCqAttrData *getLiteCqAttrData = (union OpGetLiteCqAttrData *)(inBuf + sizeof(struct MsgHead));
99 0 : unsigned int cqn = getLiteCqAttrData->txData.cqn;
100 0 : struct rdma_lite_device_cq_attr deviceCqAttr = {0};
101 :
102 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetLiteCqAttrData), sizeof(struct MsgHead), rcvBufLen, opResult);
103 :
104 0 : *opResult = gRaRsVerbsOps.getLiteCqAttr(getLiteCqAttrData->txData.phyId, getLiteCqAttrData->txData.rdevIndex, cqn,
105 : &deviceCqAttr);
106 0 : if (*opResult != 0) {
107 0 : hccp_err("get lite cq attr failed ret[%d], cqn[%u].", *opResult, cqn);
108 0 : return 0;
109 : }
110 :
111 0 : getLiteCqAttrData = (union OpGetLiteCqAttrData *)(outBuf + sizeof(struct MsgHead));
112 0 : getLiteCqAttrData->rxData.deviceCqAttr = deviceCqAttr;
113 :
114 0 : return 0;
115 : }
116 :
117 0 : int RaRsQpDestroyWithoutCQ(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
118 : {
119 : (void)outBuf;
120 : (void)outLen;
121 0 : union OpQpDestroyData *qpDestroyData = (union OpQpDestroyData *)(inBuf + sizeof(struct MsgHead));
122 :
123 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpDestroyData), sizeof(struct MsgHead), rcvBufLen, opResult);
124 :
125 0 : *opResult = gRaRsVerbsOps.qpDestroyWithoutCQ(qpDestroyData->txData.phyId, qpDestroyData->txData.rdevIndex,
126 : qpDestroyData->txData.qpn);
127 0 : if (*opResult != 0) {
128 0 : hccp_err("qp destroy without cq failed ret[%d].", *opResult);
129 : }
130 :
131 0 : return 0;
132 : }
133 :
134 0 : int RaRsGetLiteQpAttr(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
135 : {
136 : (void)outLen;
137 0 : union OpLiteQpAttrData *liteQpAttrData = (union OpLiteQpAttrData *)(inBuf + sizeof(struct MsgHead));
138 0 : union OpLiteQpAttrData *liteQpAttrOut = (union OpLiteQpAttrData *)(outBuf + sizeof(struct MsgHead));
139 :
140 : HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpLiteQpAttrData), sizeof(struct MsgHead), rcvBufLen, opResult);
141 :
142 0 : *opResult = gRaRsVerbsOps.getLiteQpAttr(liteQpAttrData->txData.phyId, liteQpAttrData->txData.rdevIndex,
143 : liteQpAttrData->txData.qpn, (void *)&liteQpAttrOut->rxData.resp);
144 0 : if (*opResult != 0) {
145 0 : hccp_err("get_lite_qp_attr failed ret[%d].", *opResult);
146 : }
147 :
148 0 : return 0;
149 : }
|