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_ADP_HW_H
12 : #define RA_ADP_HW_H
13 : #include "ra.h"
14 : #include "ra_hdc.h"
15 : #include "ra_hdc_ping.h"
16 : #include "ra_adp_async.h"
17 : #include "rs.h"
18 :
19 : #define BUCKET_DEPTH (1024 * 2)
20 : #define MAX_CFG_OP_NUM (1024 * 64)
21 : #define TOKEN_RATE 400 /* 400 tokens per 1ms */
22 : #define HDC_ACCEPT_SLEEP_TIME 100 /* 100us */
23 : #define HCCP_MAX_CHIP_ID 63U
24 : #define HAVE_OP_RIGHT 1
25 : #define HAVE_NOT_OP_RIGHT 0
26 : #define OP_RIGHT_QUERY_ERR (-1)
27 : #define TGID_INVALID 2
28 : #define RECV_BUF_LEN_INVALID 3
29 : #define HCCP_RUN_CPU_CORE 0
30 :
31 : struct RaHdcServer {
32 : HDC_SERVER hdcServer;
33 : HDC_SESSION hdcSession;
34 : struct RaHdcOpSec opSec;
35 : };
36 :
37 : struct RaHdcInitPara {
38 : unsigned int chipId;
39 : pid_t hostTgid;
40 : pthread_mutex_t mutex;
41 : unsigned int hdcFlag;
42 : unsigned int connectStatus;
43 : unsigned int threadStatus; /* 0: sleep or init; 1: running; 2: destroying */
44 : char pidSign[PROCESS_RA_SIGN_LENGTH];
45 : };
46 :
47 : struct RaOpHandle {
48 : unsigned int opcode;
49 : int (*opHandle)(char *, char *, int *, int *, int);
50 : unsigned int dataSize;
51 : };
52 :
53 : #define RA_ADP_ATTRI_VISI_DEF __attribute__((visibility("default")))
54 : RA_ADP_ATTRI_VISI_DEF int HccpInit(unsigned int chipId, pid_t pid, int hdcType, unsigned int whiteListStatus);
55 : RA_ADP_ATTRI_VISI_DEF int HccpDeinit(unsigned int chipId);
56 :
57 : #define HCCP_CHECK_PARAM_LEN(data_size, head_size, rcv_buf_len) \
58 : do { \
59 : if ((size_t)(data_size) + (size_t)(head_size) != (size_t)(rcv_buf_len)) { \
60 : hccp_err("op data size is invalid. data size:[%zu] head size:[%zu] recv buff len:[%zu]", \
61 : (size_t)(data_size), (size_t)(head_size), (size_t)(rcv_buf_len)); \
62 : return (-EINVAL); \
63 : } \
64 : } while (0)
65 :
66 : #if defined(HNS_ROCE_LLT) || defined(DEFINE_HNS_LLT)
67 : #define HCCP_CHECK_PARAM_LEN_RET_HOST(data_size, head_size, rcv_buf_len, pResult) \
68 : do { \
69 : } while (0)
70 : #else
71 : #define HCCP_CHECK_PARAM_LEN_RET_HOST(data_size, head_size, rcv_buf_len, pResult) \
72 : do { \
73 : if ((size_t)(data_size) + (size_t)(head_size) > (size_t)(rcv_buf_len)) { \
74 : hccp_err("op data size is invalid. data size:[%zu] head size:[%zu] recv buff len:[%zu]", \
75 : (size_t)(data_size), (size_t)(head_size), (size_t)(rcv_buf_len)); \
76 : *pResult = -EINVAL; \
77 : return 0; \
78 : } \
79 : } while (0)
80 : #endif
81 :
82 : #define HCCP_CHECK_PARAM_NUM(num, max_num) \
83 : do { \
84 : if ((num) > (max_num)) { \
85 : hccp_err("conn number is invalid"); \
86 : return (-EINVAL); \
87 : } \
88 : } while (0)
89 :
90 720 : static inline bool RaIsOpcodeLogSuppressed(unsigned int opcode)
91 : {
92 720 : if (opcode != RA_RS_GET_SOCKET) {
93 714 : return false;
94 : }
95 6 : return true;
96 : }
97 :
98 : void RaHdcInitOpSec(struct RaHdcOpSec *opSec, unsigned long long tokenNum, bool isAsyncOp);
99 : int RaHdcSessionAccept(unsigned int chipId, HDC_SESSION *session, int initHostTgid);
100 : int RaHdcAsyncRecvPkt(struct RaHdcAsyncInfo *asyncInfo, unsigned int chipId, void **recvBuf, unsigned int *recvLen);
101 : int RaHandle(struct RaHdcOpSec *opSec, char *recvBuf, int rcvBufLen, char **sendBuf, int *sndBufLen,
102 : unsigned int *closeSession);
103 : int RaHdcAsyncSendPkt(struct RaHdcAsyncInfo *asyncInfo, unsigned int chipId, void *sendBuf, unsigned int sendLen);
104 : void RaHdcCloseSession(HDC_SESSION *session);
105 : #endif // RA_ADP_HW_H
|