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 : #ifndef RA_RS_COMM_H
12 : #define RA_RS_COMM_H
13 : #include <stdint.h>
14 : #include <arpa/inet.h>
15 : #include <infiniband/verbs.h>
16 : #include "hccp_common.h"
17 : #include "rdma_lite_common.h"
18 : #include "ra_rs_opcode.h"
19 :
20 : #define HOST_LITE_RESERVED 4
21 : #define RA_MR_MAX_NUM 8
22 :
23 : enum {
24 : RA_RS_NOR_QP_MODE = 0,
25 : RA_RS_GDR_TMPL_QP_MODE = 1,
26 : RA_RS_OP_QP_MODE = 2,
27 : RA_RS_GDR_ASYN_QP_MODE = 3,
28 : RA_RS_OP_QP_MODE_EXT = 4,
29 : RA_RS_ERR_QP_MODE = 5,
30 : };
31 :
32 : struct OpcodeInterfaceInfo {
33 : enum OpType opcode;
34 : unsigned int version;
35 : };
36 :
37 : struct WrlistSendCompleteNum {
38 : unsigned int sendNum;
39 : unsigned int *completeNum;
40 : };
41 :
42 : struct RdmaMrRegAttr {
43 : void *addr;
44 : unsigned long long len;
45 : int access;
46 : unsigned int resv;
47 : };
48 :
49 : struct RdmaMrRegInfo {
50 : void *addr;
51 : unsigned long long len;
52 : int access;
53 : unsigned int lkey;
54 : unsigned int rkey;
55 : };
56 :
57 : struct SocketConnectInfo {
58 : unsigned int phyId;
59 : int family;
60 : union HccpIpAddr localIp;
61 : union HccpIpAddr remoteIp;
62 : unsigned int port;
63 : char tag[SOCK_CONN_TAG_SIZE];
64 : };
65 :
66 : struct SocketListenInfo {
67 : unsigned int phyId;
68 : int family;
69 : union HccpIpAddr localIp;
70 : unsigned int port;
71 : unsigned int phase;
72 : unsigned int err;
73 : };
74 :
75 : struct SocketFdData {
76 : int fd;
77 : unsigned int phyId;
78 : int family; // AF_INET(ipv4) or AF_INET6(ipv6)
79 : union HccpIpAddr localIp;
80 : union HccpIpAddr remoteIp;
81 : int status;
82 : char tag[SOCK_CONN_TAG_SIZE];
83 : };
84 :
85 : struct SocketPeerInfo {
86 : int phyId;
87 : int fd;
88 : void *socketHandle;
89 : uint32_t sslEnable;
90 : };
91 :
92 : struct QpAttrDscpInfo {
93 : unsigned char tc;
94 : unsigned char sl;
95 : };
96 :
97 : struct LiteMrInfo {
98 : uint32_t key;
99 : uint64_t addr;
100 : uint64_t len;
101 : };
102 :
103 : struct LiteRdevCapResp {
104 : struct dev_cap_info cap;
105 : unsigned char reserved[HOST_LITE_RESERVED];
106 : };
107 :
108 : struct LiteQpCqAttrResp {
109 : struct rdma_lite_device_qp_attr qpData;
110 : struct rdma_lite_device_cq_attr sendCqData;
111 : struct rdma_lite_device_cq_attr recvCqData;
112 : unsigned char reserved[HOST_LITE_RESERVED];
113 : };
114 :
115 : struct LiteQpAttrResp {
116 : struct rdma_lite_device_qp_attr qpData;
117 : unsigned char reserved[HOST_LITE_RESERVED];
118 : };
119 :
120 : struct LiteConnectedInfoResp {
121 : unsigned int state;
122 : struct LiteMrInfo localMr[RA_MR_MAX_NUM];
123 : struct LiteMrInfo remMr[RA_MR_MAX_NUM];
124 : struct QosAttr qosAttr;
125 : unsigned char reserved[HOST_LITE_RESERVED];
126 : };
127 :
128 : struct LiteMemAttrResp {
129 : struct rdma_lite_device_mem_attr memData;
130 : unsigned char reserved[HOST_LITE_RESERVED];
131 : };
132 :
133 : struct RsQpNormWithAttrs {
134 : int isExp;
135 : int isExt;
136 : struct QpExtAttrs extAttrs;
137 : unsigned int aiOpSupport;
138 : };
139 :
140 : struct RsQpRespWithAttrs {
141 : unsigned int qpn;
142 : unsigned long long aiQpAddr; // refer to struct ibv_qp *
143 : unsigned int sqIndex; // index of sq
144 : unsigned int dbIndex; // index of db
145 : unsigned int psn;
146 : unsigned int gidIdx;
147 :
148 : // below cq related info valid when data_plane_flag.bs.cq_cstm was 1
149 : unsigned long long aiScqAddr; // refer to struct ibv_cq *scq
150 : unsigned long long aiRcqAddr; // refer to struct ibv_cq *rcq
151 : struct AiDataPlaneInfo dataPlaneInfo;
152 : };
153 :
154 : struct RsQpResp {
155 : unsigned int qpn;
156 : unsigned int psn;
157 : unsigned int gidIdx;
158 : union ibv_gid gid;
159 : int directFlag;
160 : };
161 :
162 : struct RaRsDevInfo {
163 : unsigned int phyId;
164 : unsigned int devIndex;
165 : };
166 :
167 : struct TypicalQpAttr {
168 : unsigned int udpSport;
169 : int pathMtu;
170 : uint64_t vendorPrivInfo;
171 : };
172 :
173 : enum {
174 : THREAD_HALT = 0,
175 : THREAD_RUNNING = 1,
176 : THREAD_DESTROYING = 2,
177 : };
178 :
179 : enum {
180 : HDC_UNCONNECTED = 0,
181 : HDC_CONNECTED = 1,
182 : };
183 :
184 : struct TlvRequestMsgHead {
185 : unsigned int phyId;
186 : unsigned int type;
187 : unsigned int moduleType;
188 : unsigned int totalBytes;
189 : unsigned int sendBytes;
190 : unsigned int offset;
191 : };
192 :
193 : enum {
194 : CONTEXT_TYPE_JETTY = 0,
195 : CONTEXT_TYPE_JFC = 1,
196 : };
197 :
198 : #define RA_THREAD_TRY_TIME 500
199 : #define RA_THREAD_SLEEP_TIME 2000
200 : #define RA_CONNECT_TRY_TIME (500 * 120)
201 : #define HDC_TRY_TIME 200
202 : #define HDC_USLEEP_TIME 20000
203 : #define THREAD_SLEEP_TIME 100 /* 100us */
204 : #define MAX_POOL_QUEUE_SIZE_V1 512U
205 : #define MAX_POOL_QUEUE_SIZE 2048U
206 : #define MAX_POOL_THREAD_NUM 2U
207 : #define RA_POOL_THREAD_NUM 1U
208 :
209 : #define MAX_WR_NUM_V1 1024
210 : #define MAX_WR_NUM 64
211 : #define MAX_PORT_NUM 65535
212 : #define MAX_IP_INFO_NUM 128
213 : #define MAX_IP_INFO_NUM_V1 256
214 : #define MAX_SGE_NUM 16
215 : #define RA_RS_4K_PAGE_SIZE 0x1000
216 : #define HCCN_CFG_MSG_DATA_LEN 2048U
217 : #define MAX_TLV_MSG_DATA_LEN 2048U
218 : #define MAX_TLV_MSG_DATA_LEN_V2 3072U
219 :
220 : #define RA_RS_GET_IFNUM_VERSION 1
221 : #define RA_RS_WLIST_ADD_V2_VERSION 1
222 : #define RA_RS_WLIST_DEL_V2_VERSION 1
223 : #define RA_RS_SEND_WRLIST_V2_VERSION 1
224 : #define RA_RS_SEND_WRLIST_EXT_V2_VERSION 1
225 : #define RA_RS_SOCKET_CONN_VERSION 2
226 : #define RA_RS_SOCKET_LISTEN_VERSION 2
227 : #define RA_RS_GET_SOCKET_VERSION 2
228 : #define RA_RS_GET_VNIC_IP_INFOS_VERSION 1
229 : #define RA_RS_GET_NOTIFY_BA_VERSION 1
230 : #define RA_RS_OPCODE_BASE_VERSION 1
231 :
232 : #define LITE_VERSION_V2 2
233 : #define LITE_SUPPORT_DEV_MEM_REGISTER 1
234 : #define LITE_SUPPORT_PCIE_BAR_HUGE_MEM (1 << 1)
235 : #define LITE_NOT_SUPPORT 0
236 : #define LITE_ALIGN_4KB 1
237 : #define LITE_ALIGN_2MB (1 << 1)
238 :
239 : #define RA_RS_GET_ALL_IP_BIT_MASK (1U << 31)
240 :
241 : #define CQ_DEFAULT_MIN_SEND_DEPTH 64
242 : #define CQ_DEFAULT_MIN_RECV_DEPTH 64
243 : #define QP_DEFAULT_MIN_CAP_SEND_WR CQ_DEFAULT_MIN_SEND_DEPTH
244 : #define QP_DEFAULT_MIN_CAP_RECV_WR CQ_DEFAULT_MIN_RECV_DEPTH
245 : #define QP_DEFAULT_MAX_CAP_INLINE_DATA 32
246 : #define QP_DEFAULT_MIN_CAP_SEND_SGE 1
247 : #define QP_DEFAULT_MIN_CAP_RECV_SGE 1
248 : #define QP_DEFAULT_MAX_ATTR_TIMEOUT 20
249 : #define QP_DEFAULT_MAX_ATTR_RETRY_CNT 7
250 :
251 88 : static inline void RaRsSetDevInfo(struct RaRsDevInfo *devInfo, unsigned int phyId, unsigned int devIndex)
252 : {
253 88 : devInfo->phyId = phyId;
254 88 : devInfo->devIndex = devIndex;
255 88 : }
256 : #endif // RA_RS_COMM_H
|