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) do { \
58 : if ((size_t)(data_size) + (size_t)(head_size) != (size_t)(rcv_buf_len)) { \
59 : hccp_err("op data size is invalid. data size:[%zu] head size:[%zu] recv buff len:[%zu]", \
60 : (size_t)(data_size), (size_t)(head_size), (size_t)(rcv_buf_len)); \
61 : return (-EINVAL); \
62 : } \
63 : } while (0)
64 :
65 : #if defined(HNS_ROCE_LLT) || defined(DEFINE_HNS_LLT)
66 : #define HCCP_CHECK_PARAM_LEN_RET_HOST(data_size, head_size, rcv_buf_len, pResult) do { \
67 : \
68 : } while (0)
69 : #else
70 : #define HCCP_CHECK_PARAM_LEN_RET_HOST(data_size, head_size, rcv_buf_len, pResult) do { \
71 : if ((size_t)(data_size) + (size_t)(head_size) > (size_t)(rcv_buf_len)) { \
72 : hccp_err("op data size is invalid. data size:[%zu] head size:[%zu] recv buff len:[%zu]", \
73 : (size_t)(data_size), (size_t)(head_size), (size_t)(rcv_buf_len)); \
74 : *pResult = -EINVAL; \
75 : return 0; \
76 : } \
77 : } while (0)
78 : #endif
79 :
80 : #define HCCP_CHECK_PARAM_NUM(num, max_num) do { \
81 : if ((num) > (max_num)) { \
82 : hccp_err("conn number is invalid"); \
83 : return (-EINVAL); \
84 : } \
85 : } while (0)
86 :
87 720 : static inline bool RaIsOpcodeLogSuppressed(unsigned int opcode)
88 : {
89 720 : if (opcode != RA_RS_GET_SOCKET) {
90 714 : return false;
91 : }
92 6 : return true;
93 : }
94 :
95 : void RaHdcInitOpSec(struct RaHdcOpSec *opSec, unsigned long long tokenNum, bool isAsyncOp);
96 : int RaHdcSessionAccept(unsigned int chipId, HDC_SESSION *session, int initHostTgid);
97 : int RaHdcAsyncRecvPkt(struct RaHdcAsyncInfo *asyncInfo, unsigned int chipId, void **recvBuf,
98 : unsigned int *recvLen);
99 : int RaHandle(struct RaHdcOpSec *opSec, char *recvBuf, int rcvBufLen, char **sendBuf, int *sndBufLen,
100 : unsigned int *closeSession);
101 : int RaHdcAsyncSendPkt(struct RaHdcAsyncInfo *asyncInfo, unsigned int chipId, void *sendBuf,
102 : unsigned int sendLen);
103 : void RaHdcCloseSession(HDC_SESSION *session);
104 : #endif // RA_ADP_HW_H
|