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 : #ifndef RS_NDA_H
12 : #define RS_NDA_H
13 :
14 : #include "ibv_extend.h"
15 : #include "hccp_nda.h"
16 : #include "rs_rdma_inner.h"
17 : #include "rs_list.h"
18 : #include "rs.h"
19 :
20 : struct RsNdaPcieCb {
21 : struct ibv_extend_ops ibvExOps;
22 : struct RsListHead ndaDbList;
23 : };
24 :
25 : struct RsNdaUbCb {
26 : struct ibv_extend_ops ibvExOps;
27 : struct RsListHead ndaDbList;
28 : uint16_t ndaDbGuidCnt;
29 : };
30 :
31 : struct RsNdaCb {
32 : struct NdaOps ndaOps;
33 : struct RsNdaPcieCb ndaPcieCb;
34 : struct RsNdaUbCb ndaUbCb;
35 : };
36 :
37 : struct NdaPcieDbCb {
38 : uint64_t hva;
39 : uint64_t dva;
40 : uint32_t refCnt;
41 : uint32_t resv;
42 :
43 : struct RsListHead list;
44 : };
45 :
46 : struct NdaUbDbCb {
47 : uint64_t guidL;
48 : uint64_t guidH;
49 : uint64_t dva;
50 : uint16_t guidIdx;
51 : uint16_t resv;
52 : uint32_t refCnt;
53 :
54 : struct RsListHead list;
55 : };
56 :
57 : union DbUbResInfo {
58 : struct {
59 : uint32_t dbIdx : 12;
60 : uint32_t guidIdx : 16;
61 : uint32_t resv : 4;
62 : };
63 : uint32_t resId;
64 : };
65 :
66 : struct NdaUbResMapPrivInfo {
67 : unsigned long long guid_l;
68 : unsigned long long guid_h;
69 : unsigned int db_idx;
70 : unsigned int db_num;
71 : unsigned int resv[8];
72 : };
73 :
74 5 : static inline unsigned int RsNdaGenerateResId(uint32_t dbIdx, uint16_t guidIdx)
75 : {
76 5 : union DbUbResInfo resInfo = {0};
77 :
78 5 : resInfo.dbIdx = dbIdx;
79 5 : resInfo.guidIdx = guidIdx;
80 5 : return resInfo.resId;
81 : }
82 :
83 8 : static inline uint64_t AlignDown(uint64_t val, uint64_t align)
84 : {
85 8 : return (val) & ~(align - 1);
86 : }
87 :
88 4 : static inline uint64_t AlignUp(uint64_t val, uint64_t align)
89 : {
90 4 : return (val + align - 1) & ~(align - 1);
91 : }
92 :
93 : int RsInitNdaCb(struct RsRdevCb *rdevCb);
94 : void RsDeinitNdaCb(struct RsRdevCb *rdevCb);
95 : RS_ATTRI_VISI_DEF int RsNdaGetDirectFlag(unsigned int phyId, unsigned int rdevIndex, int *directFlag);
96 : RS_ATTRI_VISI_DEF int RsNdaCqCreate(unsigned int phyId, unsigned int rdevIndex, struct NdaCqInitAttr *attr,
97 : struct NdaCqInfo *info, void **ibvCqExt);
98 : RS_ATTRI_VISI_DEF int RsNdaCqDestroy(unsigned int phyId, unsigned int rdevIndex, void *ibvCqExt);
99 : RS_ATTRI_VISI_DEF int RsNdaQpCreate(unsigned int phyId, unsigned int rdevIndex, struct NdaQpInitAttr *attr,
100 : struct NdaQpInfo *info, struct RsQpResp *qpResp);
101 : RS_ATTRI_VISI_DEF int RsNdaQpDestroy(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn);
102 :
103 : #endif // RS_NDA_H
|