Line data Source code
1 : /**
2 : * Copyright (c) 2025 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 : #include <errno.h>
12 : #include "securec.h"
13 : #include "user_log.h"
14 : #include "ra_ctx_comm.h"
15 :
16 6 : int RaCtxPrepareLmemRegister(struct MrRegInfoT *lmemInfo, struct MemRegAttrT *memAttr)
17 : {
18 6 : struct RaTokenIdHandle *tokenIdHandle = NULL;
19 6 : bool isTokenIdValid = false;
20 :
21 6 : memAttr->mem = lmemInfo->in.mem;
22 6 : isTokenIdValid = lmemInfo->in.ub.flags.bs.tokenIdValid == 1;
23 6 : CHK_PRT_RETURN(isTokenIdValid && lmemInfo->in.ub.tokenIdHandle == NULL,
24 : hccp_err("[init][ra_ctx_lmem]lmem_info specify token id, but tokenIdHandle is NULL"), -EINVAL);
25 5 : memAttr->ub.flags = lmemInfo->in.ub.flags;
26 5 : memAttr->ub.tokenValue = lmemInfo->in.ub.tokenValue;
27 5 : tokenIdHandle = (struct RaTokenIdHandle *)(lmemInfo->in.ub.tokenIdHandle);
28 5 : memAttr->ub.tokenIdAddr = isTokenIdValid ? tokenIdHandle->addr : 0;
29 :
30 5 : return 0;
31 : }
32 :
33 3 : void RaCtxGetLmemInfo(struct MemRegInfoT *memInfo, struct MrRegInfoT *lmemInfo,
34 : struct RaLmemHandle *lmemHandle)
35 : {
36 3 : lmemInfo->out.key = memInfo->key;
37 3 : lmemInfo->out.ub.tokenId = memInfo->ub.tokenId;
38 3 : lmemInfo->out.ub.targetSegHandle = memInfo->ub.targetSegHandle;
39 3 : lmemHandle->addr = lmemInfo->out.ub.targetSegHandle;
40 3 : }
41 :
42 3 : void RaCtxPrepareRmemImport(struct MrImportInfoT *rmemInfo, struct MemImportAttrT *memAttr)
43 : {
44 3 : memAttr->key = rmemInfo->in.key;
45 3 : memAttr->ub.flags = rmemInfo->in.ub.flags;
46 3 : memAttr->ub.mappingAddr = rmemInfo->in.ub.mappingAddr;
47 3 : memAttr->ub.tokenValue = rmemInfo->in.ub.tokenValue;
48 3 : }
49 :
50 4 : void RaCtxPrepareCqCreate(struct CqInfoT *info, struct CtxCqAttr *cqAttr)
51 : {
52 4 : struct RaChanHandle *chanHandle = NULL;
53 :
54 4 : cqAttr->depth = info->in.depth;
55 4 : cqAttr->ub.userCtx = info->in.ub.userCtx;
56 4 : cqAttr->ub.mode = info->in.ub.mode;
57 4 : cqAttr->ub.ceqn = info->in.ub.ceqn;
58 4 : cqAttr->ub.flag = info->in.ub.flag;
59 4 : if (info->in.chanHandle != NULL) {
60 1 : chanHandle = (struct RaChanHandle *)info->in.chanHandle;
61 1 : cqAttr->chanAddr = chanHandle->addr;
62 : }
63 4 : }
64 :
65 3 : void RaCtxGetCqCreateInfo(struct CtxCqInfo *cqInfo, struct CqInfoT *info)
66 : {
67 3 : info->out.va = cqInfo->addr;
68 3 : info->out.id = cqInfo->ub.id;
69 3 : info->out.cqeSize = cqInfo->ub.cqeSize;
70 3 : info->out.bufAddr = cqInfo->ub.bufAddr;
71 3 : info->out.swdbAddr = cqInfo->ub.swdbAddr;
72 3 : }
73 :
74 8 : int RaCtxPrepareQpCreate(struct QpCreateAttr *qpAttr, struct CtxQpAttr *ctxQpAttr)
75 : {
76 8 : struct RaTokenIdHandle *tokenIdHandle = NULL;
77 :
78 8 : CHK_PRT_RETURN(qpAttr->scqHandle == NULL, hccp_err("[init][ra_ctx_qp]scq_handle is NULL"), -EINVAL);
79 7 : CHK_PRT_RETURN(qpAttr->rcqHandle == NULL, hccp_err("[init][ra_ctx_qp]rcq_handle is NULL"), -EINVAL);
80 :
81 6 : ctxQpAttr->scqIndex = ((struct RaCqHandle *)qpAttr->scqHandle)->addr;
82 6 : ctxQpAttr->rcqIndex = ((struct RaCqHandle *)qpAttr->rcqHandle)->addr;
83 6 : ctxQpAttr->srqIndex = 0;
84 6 : ctxQpAttr->sqDepth = qpAttr->sqDepth;
85 6 : ctxQpAttr->rqDepth = qpAttr->rqDepth;
86 6 : ctxQpAttr->transportMode = qpAttr->transportMode;
87 :
88 6 : ctxQpAttr->ub.mode = qpAttr->ub.mode;
89 6 : ctxQpAttr->ub.jettyId = qpAttr->ub.jettyId;
90 6 : ctxQpAttr->ub.flag = qpAttr->ub.flag;
91 6 : ctxQpAttr->ub.jfsFlag = qpAttr->ub.jfsFlag;
92 6 : ctxQpAttr->ub.tokenValue = qpAttr->ub.tokenValue;
93 6 : ctxQpAttr->ub.priority = qpAttr->ub.priority;
94 6 : ctxQpAttr->ub.rnrRetry = qpAttr->ub.rnrRetry;
95 6 : ctxQpAttr->ub.errTimeout = qpAttr->ub.errTimeout;
96 :
97 6 : if (qpAttr->ub.tokenIdHandle != NULL) {
98 1 : tokenIdHandle = (struct RaTokenIdHandle *)(qpAttr->ub.tokenIdHandle);
99 1 : ctxQpAttr->ub.tokenIdAddr = tokenIdHandle->addr;
100 : }
101 :
102 6 : return 0;
103 : }
104 :
105 4 : void RaCtxGetQpCreateInfo(struct RaCtxHandle *ctxHandle, struct QpCreateAttr *qpAttr,
106 : struct QpCreateInfo *qpInfo, struct RaCtxQpHandle *qpHandle)
107 : {
108 4 : qpHandle->devIndex = ctxHandle->devIndex;
109 4 : qpHandle->phyId = ctxHandle->attr.phyId;
110 4 : qpHandle->ctxHandle = ctxHandle;
111 4 : qpHandle->protocol = ctxHandle->protocol;
112 4 : qpHandle->id = qpInfo->ub.id;
113 4 : (void)memcpy_s(&qpHandle->qpAttr, sizeof(struct QpCreateAttr), qpAttr, sizeof(struct QpCreateAttr));
114 4 : (void)memcpy_s(&qpHandle->qpInfo, sizeof(struct QpCreateInfo), qpInfo,
115 : sizeof(struct QpCreateInfo));
116 4 : }
117 :
118 4 : void RaCtxPrepareQpImport(struct QpImportInfoT *qpInfo, struct RaRsJettyImportAttr *importAttr)
119 : {
120 4 : importAttr->mode = qpInfo->in.ub.mode;
121 4 : importAttr->tokenValue = qpInfo->in.ub.tokenValue;
122 4 : importAttr->policy = qpInfo->in.ub.policy;
123 4 : importAttr->type = qpInfo->in.ub.type;
124 4 : importAttr->flag = qpInfo->in.ub.flag;
125 4 : importAttr->expImportCfg = qpInfo->in.ub.expImportCfg;
126 4 : importAttr->tpType = qpInfo->in.ub.tpType;
127 4 : }
128 :
129 2 : void RaCtxGetQpImportInfo(struct RaCtxHandle *ctxHandle, struct QpImportInfoT *qpInfo,
130 : struct RaRsJettyImportInfo *importInfo, struct RaCtxRemQpHandle *qpHandle)
131 : {
132 2 : qpInfo->out.ub.tjettyHandle = importInfo->tjettyHandle;
133 2 : qpInfo->out.ub.tpn = importInfo->tpn;
134 2 : qpHandle->devIndex = ctxHandle->devIndex;
135 2 : qpHandle->phyId = ctxHandle->attr.phyId;
136 2 : qpHandle->protocol = ctxHandle->protocol;
137 2 : qpHandle->qpKey = qpInfo->in.key;
138 2 : }
|